dev-master
9999999-dev
The Requires
- php >=5.4
The Development Requires
Wallogit.com
2017 © Pedro Peláez
This a very slightly modified version of Etsy's StatsD example for PHP. The Counter class provides a static registry (It's a singleton. Don't even start.) for StatsD instance, allowing it to be accessed from every nook and cranny of an application., (*1)
This library is best installed using Composer. Include the generated Composer autoloader (usually vendor/autoload.php)., (*2)
The StatsD class has two constructor arguments, host and port., (*3)
The bare minimum you need to do is instantiate StatsD with your server settings and you're good to go., (*4)
To make sending metrics more accessible around your application, you can use the Counter static registry., (*5)
$statsD = new StatsD($myHost, $myPort);
Counter::setInstance($statsD);
...
Counter::increment('hits');
MockStatsD
If you need to test that a class is sending statistics as you expect, you can create an instance of MockStatsD, which can report on the current value of counters being incremented/decremented. At present, MockStatsD can only report on counters., (*6)
$statsD = new MockStatsD();
Counter::setInstance($statsD);
... test test test ...
$fooCount = $statsD->getCounter('foo');