PHP code example of lazyshot / prometheus-php

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

    

lazyshot / prometheus-php example snippets




$client = new Prometheus\Client('http://localhost:9091/metrics/job/');

	$counter = $client->newCounter([
		'namespace' => 'php_client',
		'subsystem' => 'testing',
		'name' => 'counter',
		'help' => 'Testing the PHPClients Counter',
	]);

	$counter->increment( [ 'url' => 'home.php', 'status_code' => 200 ], rand( 1, 50 ) );
	$counter->increment( [ 'url' => 'home.php', 'status_code' => 404 ], rand( 1, 50 ) );

	$client->pushMetrics( "pretend_server", $job_id );

	
	$client = new Prometheus\Client('http://localhost:9091/metrics/job/');

	$counter = $client->newCounter([
		'namespace' => 'php_client',
		'subsystem' => 'testing',
		'name' => 'counter',
		'help' => 'Testing the PHPClients Counter',
	]);

	$counter->increment( [ 'url' => 'home.php', 'status_code' => 200 ], rand( 1, 50 ) );
	$counter->increment( [ 'url' => 'home.php', 'status_code' => 404 ], rand( 1, 50 ) );

	$client->pushMetrics( "pretend_server", "test_instance" );

	echo $client->serialize();