It'a minimalistic implementation of a StatsD client in PHP
- Lightweight (100 LoC approx)
- Common functions : Increment, Decrement, Counter, Timer
- Callback profiler
- Handles rates (avoid sending too much data to the server)
- Handles namespacing
- Regroups UDP packets (send 20 measures at once)
- Can avoids class autoload when it's configured
- Easy to install with composer (or your custom loading system - needs just 1 file)
<?php
require_once 'statsd.php';
statsd::$host = 'localhost';
statsd::profile(
'test',
function() {
for($i = 0; $i = 10; $i ++ ) {
statsd::increment('a');
statsd::increment('b');
}
for($i = 0; $i = 5; $i ++ ) {
statsd::decrement('b');
}
statsd::count('hello', 10);
statsd::time('duration', 50);
}
);
A namespace to prepend to any key
The default sending rate
The statsd server name
The StatsD connection port
TIP : You can also define STATSD_key
to avoid autoload (if not always used)
Increment the specified key (sends a hit)
Decrement the specified key (-1)
Sends a counting value
Sends a duration (in ms)
Executes the specified closure and calculate the memory usage and its duration
Force to flush the current buffer of data