Datadogstatsd::service_check PHP Méthode

service_check() public static méthode

Send a custom service check status over UDP
public static service_check ( string $name, integer $status, array $tags = null, string $hostname = null, string $message = null, integer $timestamp = null ) : null
$name string service check name
$status integer service check status code (see static::OK, static::WARNING,...)
$tags array Key Value array of Tag => Value, or single tag as string
$hostname string hostname to associate with this service check status
$message string message to associate with this service check status
$timestamp integer timestamp for the service check status (defaults to now)
Résultat null
    public static function service_check($name, $status, array $tags = null, $hostname = null, $message = null, $timestamp = null)
    {
        $msg = "_sc|{$name}|{$status}";
        if ($timestamp !== null) {
            $msg .= sprintf("|d:%s", $timestamp);
        }
        if ($hostname !== null) {
            $msg .= sprintf("|h:%s", $hostname);
        }
        if ($tags !== null && is_array($tags) && count($tags) > 0) {
            $msg .= sprintf('|#%s', join(',', $tags));
        } elseif (isset($tags) && !empty($tags)) {
            $msg .= sprintf('|#%s', $tags);
        }
        if ($message !== null) {
            $msg .= sprintf('|m:%s', static::escape_sc_message($message));
        }
        static::report($msg);
    }

Usage Example

<?php

require '../libraries/datadogstatsd.php';
Datadogstatsd::increment('web.page_views');
Datadogstatsd::histogram('web.render_time', 15);
Datadogstatsd::set('web.uniques', 3);
Datadogstatsd::service_check('my.service.check', Datadogstatsd::CRITICAL);
//All the following metrics will be sent in a single UDP packet to the statsd server
BatchedDatadogstatsd::increment('web.page_views');
BatchedDatadogstatsd::histogram('web.render_time', 15);
BatchedDatadogstatsd::set('web.uniques', 3);
BatchedDatadogstatsd::flush_buffer();
// Necessary