02/11
2017
Wallogit.com
2017 © Pedro Peláez
Sends stats to Statsd.
Simple PHP library to send stats to statsd., (*1)
Add the dependency to your composer.json., (*2)
{
"require": {
"shazam/php-statsd": "2.*"
}
}
An example of how to send metrics of how long it takes to load a page., (*3)
<?php
use Statsd;
// $config = array(...);
// $path = ...
// initialize client
$configuration = new Statsd\Client\Configuration();
$configuration->setHost($config['host'])
->setNamespace($config['namespace']);
$statsClient = new Statsd\Client($configuration);
// add stats (you can also add an array of stats with addStats())
$statsClient->addStat(
array(
'namespace' => 'endpoints.' . $path, // that will be your stat namespace
'value' => $executionTime, // calculate it in microseconds
'type' => 'ms'
)
);
// send them
$statsClient->sendStats();
You can use TIME_MS, COUNT, GAUGE or SET (ms, c, g, s) as type of stats., (*4)
An example of a config file for that client could be:, (*5)
stats:
enable: true
client:
host: 127.0.0.1
namespace: shazam.twitterhose