PHP code example of league / statsd

1. Go to this page and download the library: Download league/statsd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

league / statsd example snippets


$statsd = new League\StatsD\Client();
$statsd->configure([
    'host' => '127.0.0.1',
    'port' => 8125,
    'namespace' => 'example'
]);

$statsd1 = StatsD\Client::instance('server1')->configure([...]);
$statsd2 = StatsD\Client::instance('server2')->configure([...]);

$statsd->increment('web.pageview');
$statsd->decrement('storage.remaining');
$statsd->increment([
    'first.metric',
    'second.metric'
], 2);
$statsd->increment('web.clicks', 1, 0.5);

$statsd->gauge('api.logged_in_users', 123456);

$userID = 23;
$statsd->set('api.unique_logins', $userID);

$statsd->timing('api.response_time', 256);

$metrics = array('api.response_time' => 256, 'api.memory' => 4096));
$statsd->timings($metrics);

$statsd->time('api.dbcall', function () {
    // this code execution will be timed and recorded in ms
});

$statsd->configure([
    'tags' => ['some_general_tag' => 'value']
]);

$statsd->increment('web.clicks', 1, 1, ['host' => $_SERVER['HTTP_HOST']]);

    'providers' => [
        // ...
        'League\StatsD\Laravel\Provider\StatsdServiceProvider',
    ]

    'aliases' => [
        // ...
        'Statsd' => 'League\StatsD\Laravel\Facade\StatsdFacade',
    ]

    'providers' => [
        // ...
        League\StatsD\Laravel5\Provider\StatsdServiceProvider::class,
    ]

    'aliases' => [
        // ...
        'Statsd' => League\StatsD\Laravel5\Facade\StatsdFacade::class,
    ]

$app->register(\League\StatsD\Laravel5\Provider\StatsdServiceProvider::class);

STATSD_HOST=127.0.0.1
STATSD_PORT=8125
STATSD_NAMESPACE=
boostrap/app.php
statsd.php