public static function StatsD::send in StatsD 6
Same name and namespace in other branches
- 7.2 includes/statsd.inc \StatsD::send()
- 7 includes/statsd.inc \StatsD::send()
3 calls to StatsD::send()
- StatsD::gauge in includes/
statsd.inc - Sends a gauge, an arbitrary value to statsd
- StatsD::timing in includes/
statsd.inc - Log timing information
- StatsD::updateStats in includes/
statsd.inc - Updates one or more stats counters by arbitrary amounts.
File
- includes/
statsd.inc, line 106
Class
- StatsD
- Sends statistics to the stats daemon over UDP
Code
public static function send($data, $sample_rate = NULL) {
if (!variable_get('statsd_enabled', FALSE)) {
return;
}
$sample_rate = $sample_rate ? $sample_rate : variable_get('statsd_sample_rate', 1);
$sampled_data = array();
$data = self::prefixData($data);
if ($sample_rate < 1) {
foreach ($data as $stat => $value) {
if (mt_rand() / mt_getrandmax() <= $sample_rate) {
$sampled_data[$stat] = "{$value}|@{$sample_rate}";
}
}
}
else {
$sampled_data = $data;
}
if (empty($sampled_data)) {
return;
}
$host = variable_get('statsd_host', '127.0.0.1');
$port = variable_get('statsd_port', 8125);
$fp = stream_socket_client("udp://{$host}:{$port}", $errno, $errstr);
if ($fp) {
stream_set_blocking($fp, 0);
foreach ($sampled_data as $stat => $value) {
fwrite($fp, "{$stat}:{$value}");
}
fclose($fp);
}
}