3 [![Build Status](https://secure.travis-ci.org/liuggio/statsd-php-client.png)](http://travis-ci.org/liuggio/statsd-php-client) [![Latest Stable Version](https://poser.pugx.org/liuggio/statsd-php-client/v/stable.png)](https://packagist.org/packages/liuggio/statsd-php-client) [![Total Downloads](https://poser.pugx.org/liuggio/statsd-php-client/downloads.png)](https://packagist.org/packages/liuggio/statsd-php-client)
5 `statsd-php-client` is an Open Source, and **Object Oriented** Client for **etsy/statsd** written in php
7 ### Install with composer
10 composer require liuggio/statsd-php-client
16 $statsd = new StatsdService();
18 $service->timing('usageTime', 100);
19 $service->increment('visitor');
20 $service->decrement('click');
21 $service->gauge('gaugor', 333);
22 $service->set('uniques', 765);
28 ## Why use this library instead the [statsd/php-example](https://github.com/etsy/statsd/blob/master/examples/php-example.php)?
32 - You could also use monolog to redirect data to statsd
34 - This library is tested.
36 - This library optimizes the messages to send, compressing multiple messages in individual UDP packets.
38 - This library pays attention to the maximum length of the UDP.
40 - This library is made by Objects not array, but it also accepts array.
42 - You do want to debug the packets, and using `SysLogSender` the packets will be logged in your `syslog` log (on debian-like distro: `tail -f /var/log/syslog`)
45 ### Advanced Instantiation
48 use Liuggio\StatsdClient\StatsdClient,
49 Liuggio\StatsdClient\Factory\StatsdDataFactory,
50 Liuggio\StatsdClient\Sender\SocketSender,
51 Liuggio\StatsdClient\Service\StatsdService;
52 // use Liuggio\StatsdClient\Sender\SysLogSender;
54 $sender = new SocketSender(/*'localhost', 8126, 'udp'*/);
55 // $sender = new SysLogSender(); // enabling this, the packet will not send over the socket
57 $client = new StatsdClient($sender);
58 $factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData');
59 $service = new StatsdService($client, $factory);
61 // create the metrics with the service
62 $service->timing('usageTime', 100);
66 // send the data to statsd
71 ### Usage with Monolog
74 use Liuggio\StatsdClient\StatsdClient,
75 Liuggio\StatsdClient\Factory\StatsdDataFactory,
76 Liuggio\StatsdClient\Sender\SocketSender;
77 // use Liuggio\StatsdClient\Sender\SysLogSender;
80 use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler;
82 $sender = new SocketSender(/*'localhost', 8126, 'udp'*/);
83 // $sender = new SysLogSender(); // enabling this, the packet will not send over the socket
84 $client = new StatsdClient($sender);
85 $factory = new StatsdDataFactory();
87 $logger = new Logger('my_logger');
88 $logger->pushHandler(new StatsDHandler($client, $factory, 'prefix', Logger::DEBUG));
90 $logger->addInfo('My logger is now ready');
93 the output will be: `prefix.my_logger.INFO.My-logger:1|c" 36 Bytes`
97 ### Easily Install StatSD and Graphite
99 In order to try this application monitor you have to install etsy/statsd and Graphite
101 see this blog post to install it with vagrant [Easy install statsd graphite](http://welcometothebundle.com/easily-install-statsd-and-graphite-with-vagrant/).
103 #### [StatsD](https://github.com/etsy/statsd)
105 StatsD is a simple daemon for easy stats aggregation
107 #### [Graphite](http://graphite.wikidot.com/)
109 Graphite is a Scalable Realtime Graphing
111 #### The Client sends data with UDP (faster)
113 https://www.google.com/search?q=tcp+vs+udp
117 Active contribution and patches are very welcome.
118 To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please
119 make sure that they are still passing and if you add functionality please
120 take a look at the coverage as well it should be pretty high :)
122 - First fork or clone the repository
125 git clone git://github.com/liuggio/statsd-php-client.git
132 composer.phar install
135 - This will give you proper results:
138 phpunit --coverage-html reports
143 This project is actively mantained by David Moreau AKA @dav-m85 and @liuggio