Small PHP client which pushes data over UDP to a stats.d server. Feature suggestions and feedback is always welcome.
- Add this client to the dependencies
- Configure StatsD
- Register namespace
- Register StatsD as a service
Add the following lines to your deps
-file.
[StatsDClient]
git=git://github.com/DigitalPioneers/StatsDClient.git
target=/statsd
Now, run the vendors script to download the client:
php bin/vendors install
This client is available as a package in packagist. You simply have to add digital-pioneers/statsd-client
to the require
-section of your composer.json
.
{
"require": {
"php": "digital-pioneers/statsd-client",
}
}
Now, run the vendors script to download the client:
php composer.phar install
The Client needs to know where your StatsD is running. Add the following lines to your parameters.ini
.
statsd.host = "<IP or Host of your stats.d Server, default 127.0.0.1>"
statsd.port = "<Port of your stats.d Server, default 8125>"
Register the namespace StatsD in app/autoload.php
.
$loader->registerNamespaces(
array(
/// (...)
'StatsD' => SYMFONY_VENDOR_PATH . '/statsd/src',
/// (...)
));
Composer should've registered the namespace properly.
Now add the following lines to your config.yml
and you're good to go.
services:
statsd:
class: StatsD\StatsD
arguments: [%statsd.host%, %statsd.port%]
The StatsD Client is accessible as a service through the container. It offers various methods to manipulate your statistics.
Take a look at the following example to understand how to use the Client.
$statsd = $this->get('statsd');
$statsd->increment('mypage.visits');
For further informations on the functions offered take a look at the StatsD.php.