Wallogit.com
2017 © Pedro Peláez
Sends statistics to a statsd daemon over UDP
Send statistics to the statsd daemon over UDP., (*1)
This class generally follows the official php-example from Etsy, but moves the configuration options into the main class with reasonable defaults. This should make incorporation into framework-based applications more straightforward., (*2)
Installation is via composer:, (*3)
composer require stevenscg/statsd-php
The library can be configured by calling StatsD::config($params)., (*4)
$params is an array that supports the following keys:, (*5)
enabled - boolean - Set to false to disable UDP transmission (default: true), (*6)
prefix - string - Apply a global namespace to all metrics from this application, (*7)
host - string - Hostname or IP of your carbon/graphite server, (*8)
port - integer - StatsD port of your carbon/graphite server, (*9)
The library can also be configured via environment variables:, (*10)
STATSD_ENABLED - A boolean-like string (i.e. true, false, 1, 0), (*11)
STATSD_PREFIX - string, (*12)
STATSD_ADDR - string - Example: 127.0.0.1:8125, (*13)
Counting - increment and decrement, (*14)
Timing - timing, (*15)
Sampling - supported via "sampleRate" parameter on increment and decrement, (*16)
Gauges - gauge, (*17)
Sets - set, (*18)
All methods are declared as static as they were in the upstream project., (*19)
Incrementing a counter is as simple as:, (*20)
StatsD::increment("api.requests");
Example: Tracking logins and failures, (*21)
function login() {
...
if (!$this->Auth->login()) {
StatsD::increment("logins.failed");
return;
}
StatsD::increment("logins.ok");
...
}
MIT, (*22)