PHP code example of okvpn / datadog-symfony

1. Go to this page and download the library: Download okvpn/datadog-symfony 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/ */

    

okvpn / datadog-symfony example snippets



return [
    ... //  bundles
    Okvpn\Bundle\DatadogBundle\OkvpnDatadogBundle::class => ['all' => true], 
    ...
]

$client = $this->container->get('okvpn_datadog.client'); // Default public alias 

// okvpn_datadog.client.default - private services
// okvpn_datadog.client.i2pd_client
// okvpn_datadog.client.null

class FeedController 
{
    public function __construct(private DogStatsInterface $dogStats){} // default 
}

class FeedController 
{
    public function __construct(private DogStatsInterface $i2pdClient){} // i2pd_client
}

class FeedController extends Controller
{
    // Inject via arg for Symfony 4+
    #[Route(path: '/', name: 'feeds')]
    public function feedsAction(DogStatsInterface $dogStats, DogStatsInterface $i2pdClient): Response
    {
        $dogStats->decrement('feed');
        
        return $this->render('feed/feeds.html.twig');
    }
}

class FeedController extends Controller
{
    // Inject via arg for Symfony 4+
    #[Route(path: '/', name: 'feeds')]
    public function feedsAction(DogStatsInterface $dogStats): Response
    {
        $dogStats->decrement('feed');
        
        return $this->render('feed/feeds.html.twig');
    }
}

// or use service directly for 3.4
$client = $this->container->get('okvpn_datadog.client');

/*
 * Increment/Decriment
 * 
 * Counters track how many times something happens per second, such as page views.
 * @link https://docs.datadoghq.com/developers/dogstatsd/data_types/#counters
 *
 * @param string          $metrics    Metric(s) to increment
 * @param int             $delta      Value to decrement the metric by
 * @param float           $sampleRate Sample rate of metric
 * @param string[]        $tags       List of tags for this metric
 *
 * @return DogStatsInterface
 */
$client->increment('page.views', 1);
$client->increment('page.load', 1, 0.5, ['tag1' => 'http']);


$consumerPid = getmypid();
$client->set('consumers', $consumerPid);

$client->timing('http.response_time', 256);
yaml
okvpn_datadog:
    clients:
        default: 'datadog://127.0.0.1/namespace'
        
        ## More clients
        i2pd_client: 'datadog://10.10.1.1:8125/app?tags=tg1,tg2'
        'null': null://null
        mock: mock://mock
        dns: '%env(DD_CLIENT)%'