1. Go to this page and download the library: Download ml65/prometheus_client_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/ */
ml65 / prometheus_client_php example snippets
\Prometheus\CollectorRegistry::getDefault()
->getOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement')
->inc();
$registry = \Prometheus\CollectorRegistry::getDefault();
$counterA = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counterA->incBy(3, ['blue']);
// once a metric is registered, it can be retrieved using e.g. getCounter:
$counterB = $registry->getCounter('test', 'some_counter')
$counterB->incBy(2, ['red']);
\Prometheus\Storage\Redis::setDefaultOptions(
[
'host' => '127.0.0.1', // host redis server or sentinel server
'port' => 6379, // port redis server or sentinel server
'password' => null,
'timeout' => 0.1, // in seconds
'read_timeout' => '10', // in seconds
'persistent_connections' => false,
'sentinels' => false, // support sentinel . Before requesting to redis, a request is made to the sentinel to get
// the address and port of the master redis server.
]
);