PHP code example of chaseisabelle / phprom-bundle
1. Go to this page and download the library: Download chaseisabelle/phprom-bundle 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/ */
chaseisabelle / phprom-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...
new ChaseIsabelle\PHPromBundle\ChaseIsabellePHPromBundle(),
);
...
namespace App\Controller;
use ChaseIsabelle\PHPromBundle\Service\PHPromService;
use Exception;
use PHProm\Timer;
use Symfony\Component\HttpFoundation\Response;
/**
* @package App\Controller
*/
class DefaultController
{
/**
* @param PHPromService $phpromService
* @return Response
* @throws Exception
*/
public function index(PHPromService $phpromService)
{
$counter = $phpromService->counter()
->setName('custom_counter')
->setDescription('my custom counter')
->setLabels(['foo']); //<< optional
$counter->record(
rand(1, 10),
['foo' => 'bar'] //<< optional
);
$histogram = $phpromService->histogram()
->setName('custom_histogram')
->setDescription('my custom histogram')
->setLabels(['foo']) //<< optional
->setBuckets(range(1, 10)); //<< optional
$histogram->record(
rand(1, 100) / 10,
['foo' => 'bar'] //<< optional
);
$timer = new Timer($histogram);
$timer->start();
// do something
$timer->stop()
->record(['foo' => 'bar'])
->reset();
$summary = $phpromService->summary()
->setName('custom_summary')
->setDescription('my custom summary')
->setLabels(['foo']) //<< optional
->setObjectives(range(1, 5)) //<< optional
->setAgeBuckets(5) //<< optional
->setMaxAge(10) //<< optional
->setBufCap(5); //<< optional
$summary->record(
rand(1, 100) / 10,
['foo' => 'bar'] //<< optional
);
$gauge = $phpromService->gauge()
->setName('custom_gauge')
->setDescription('my custom gauge')
->setLabels(['foo']); //<< optional
$gauge->record(
rand(1, 10),
['foo' => 'bar'] //<< optional
);
return new Response($phpromService->instance()->get(), 200, [
'Content-Type' => 'text/plain'
]);
}
}