PHP code example of tweedegolf / prometheus-client

1. Go to this page and download the library: Download tweedegolf/prometheus-client 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/ */

    

tweedegolf / prometheus-client example snippets


use TweedeGolf\PrometheusClient\CollectorRegistry;
use TweedeGolf\PrometheusClient\Storage\ApcuAdapter;

$registry = new CollectorRegistry(new ApcuAdapter());
$registry->createCounter('requests', [], null, true);
$registry->createGauge('traffic', ['endpoint'], 'Active traffic per endpoint', true);

$registry->getCounter('requests')->inc();
$registry->getGauge('traffic')->set(10, ['/home']);

use TweedeGolf\PrometheusClient\Format\TextFormatter;

$formatter = new TextFormatter();
header('Content-Type', $formatter->getMimeType());
echo $formatter->format($registry->collect());