Permalink
Browse files

added debug option, and syslog information

  • Loading branch information...
1 parent d97b13e commit d0500863cec2ea1445e662939ac5cfe299eb804c @liuggio committed Mar 18, 2013
@@ -12,6 +12,12 @@
*/
class Configuration implements ConfigurationInterface
{
+ private $debug;
+
+ public function __construct($debug)
+ {
+ $this->debug = $debug;
+ }
/**
* {@inheritDoc}
*/
@@ -25,9 +31,12 @@ public function getConfigTreeBuilder()
->booleanNode('enable_collector')->defaultFalse()->end()
->arrayNode('connection')
->children()
+ ->scalarNode("class")->defaultValue('Liuggio\StatsdClient\Sender\SocketSender')->end()
+ ->scalarNode("debug_class")->defaultValue('Liuggio\StatsdClient\Sender\SysLogSender')->end()
+ ->scalarNode("debug")->defaultValue($this->debug)->end()
->scalarNode("port")->defaultValue(8125)->end()
->scalarNode("host")->defaultValue("localhost")->end()
- ->scalarNode("reduce_packet")->defaultValue("true")->end()
+ ->scalarNode("reduce_packet")->defaultValue(true)->end()
->scalarNode("protocol")->defaultValue("udp")->end()
->scalarNode("fail_silently")->defaultValue(true)->end()
->end()
@@ -25,9 +25,12 @@ class LiuggioStatsDClientExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
- $configuration = new Configuration();
+ $configuration = new Configuration($container->getParameter('kernel.debug'));
$config = $this->processConfiguration($configuration, $configs);
+ $container->setParameter($this->getAlias() . '.sender.class', $config['connection']['class']);
+ $container->setParameter($this->getAlias() . '.sender.debug_class', $config['connection']['debug_class']);
+
foreach ($config['connection'] as $k => $v) {
$container->setParameter($this->getAlias() . '.connection.' . $k, $v);
}
@@ -54,6 +57,12 @@ public function load(array $configs, ContainerBuilder $container)
if ($config['monolog'] && $config['monolog']['enable']) {
$this->loadMonologHandler($config, $container);
}
+ // set the debug sender
+ if ($config['connection']['debug']) {
+ $senderService = new Definition('%liuggio_stats_d_client.sender.debug_class%');
+ $container->setDefinition('liuggio_stats_d_client.sender.service', $senderService);
+ $senderService->setArguments(array());
+ }
}
private function convertLevelToConstant($level)
View
@@ -46,7 +46,19 @@ Within this bundle you could use ready-to-go monitor for
- Amount of PHP ram used
-- You could create your own using the Factory and the Service.
+- You could create your own using the Factory and the Service.
+
+### Easy Debug
+
+If debug mode is enabled no packet are sent over the udp socket, and you could see what's going on reading the syslog with `tail -f /var/log/syslog`
+
+```log
+Mar 19 00:48:11 liuggio nginx: statsd-open
+Mar 19 00:48:11 liuggio nginx: statsd-write "tvision.visitor:1|tvision.memory:43520|tvision.user.anonymous:1|tvision.query.start:1|tvision.query.insert:1|c" 118 Bytes
+Mar 19 00:48:11 liuggio nginx: statsd-close
+```
+
+Note: by default in `dev` environment debug is true.
One UDP packet to rule them all
@@ -2,9 +2,7 @@ parameters:
liuggio_stats_d_client.service.class: Liuggio\StatsdClient\StatsdClient
liuggio_stats_d_client.entity.class: Liuggio\StatsdClient\Entity\StatsdData
liuggio_stats_d_client.factory.class: Liuggio\StatsdClient\Factory\StatsdDataFactory
-
- liuggio_stats_d_client.socket.service.class: Liuggio\StatsdClient\Sender\SocketSender
-
+ liuggio_stats_d_client.sender.debug.class: Liuggio\StatsdClient\Sender\EchoSender
liuggio_stats_d_client.collector.service.class: Liuggio\StatsDClientBundle\Service\StatsDCollectorService
liuggio_stats_d_client.collector.listener.class: Liuggio\StatsDClientBundle\Listener\StatsDCollectorListener
liuggio_stats_d_client.collector.dbal.class: Liuggio\StatsDClientBundle\StatsCollector\DbalStatsCollector
@@ -19,12 +17,13 @@ services:
class: %liuggio_stats_d_client.factory.class%
arguments: [%liuggio_stats_d_client.entity.class%]
- liuggio_stats_d_client.socket.service:
- class: %liuggio_stats_d_client.socket.service.class%
+ liuggio_stats_d_client.sender.service:
+ class: %liuggio_stats_d_client.sender.class%
+ arguments: [%liuggio_stats_d_client.connection.host%, %liuggio_stats_d_client.connection.port%, %liuggio_stats_d_client.connection.protocol%]
liuggio_stats_d_client.service:
class: %liuggio_stats_d_client.service.class%
- arguments: [@liuggio_stats_d_client.socket.service, %liuggio_stats_d_client.connection.host%, %liuggio_stats_d_client.connection.port%,%liuggio_stats_d_client.connection.protocol%, %liuggio_stats_d_client.connection.reduce_packet%, %liuggio_stats_d_client.connection.fail_silently%]
+ arguments: [@liuggio_stats_d_client.sender.service, %liuggio_stats_d_client.connection.reduce_packet%, %liuggio_stats_d_client.connection.fail_silently%]
# collector service
liuggio_stats_d_client.collector.service:
@@ -132,8 +132,6 @@ Working with Personal Collector
If the information from Monolog is not enough for you, you can use the Collectors that collect the information and then send the data to the StatsD Server.
-
-
``` yaml
# app/config/config.yml
@@ -187,6 +185,9 @@ liuggio_stats_d_client:
level: 'warning'
context_logging: true
connection:
+ class: Liuggio\StatsdClient\Sender\SocketSender
+ debug_class: Liuggio\StatsdClient\Sender\ErrorLogSender
+ debug: %kernel.debug%
host: localhost
port: 8125
protocol: udp

0 comments on commit d050086

Please sign in to comment.