1. Go to this page and download the library: Download clivern/metric 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/ */
clivern / metric example snippets
use Clivern\Observability\Aggregation\MemcachedAggregate;
use Clivern\Observability\Aggregation\Client\MemcachedClient;
use Clivern\Observability\Reporter\GraphiteClient;
$metricsReporter = new MemcachedAggregate(
new GraphiteClient('localhost', 2003),
new MemcachedClient('127.0.0.1', 11211),
[]
);
$metricsReporter->report([
[
'key' => 'orders_service.metrics.total_http_calls',
'value' => 1,
'time' => time(),
'aggregateFunc' => MemcachedAggregate::SUM_AGGREGATE_FUNCTION
]
]);
use Clivern\Observability\Stats\Execution;
$execution = new Execution();
$execution->start();
// Code that takes time!
sleep(2);
$execution->end();
var_dump($execution->getTimeInSeconds()); // float
var_dump($execution->getTimeInMinutes()); // float
use Clivern\Observability\Aggregation\MemcachedAggregate;
use Clivern\Observability\Aggregation\Client\MemcachedClient;
use Clivern\Observability\Reporter\GraphiteClient;
$metricsReporter = new MemcachedAggregate(
new GraphiteClient('localhost', 2003),
new MemcachedClient('127.0.0.1', 11211),
[]
);
$execution = new Execution();
$execution->start();
// Code that takes time!
sleep(2);
$execution->end();
$metricsReporter->report([
[
'key' => 'orders_service.metrics.http_request_latency',
'value' => $execution->getTimeInSeconds(),
'time' => time(),
'aggregateFunc' => MemcachedAggregate::AVG_AGGREGATE_FUNCTION
]
]);
#
zsh
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.