chaseisabelle / phprom-bundle
Symfony 4 PHProm Bundle
Installs: 873
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
- chaseisabelle/phprom-client: >=0.0.5
- symfony/config: ^4.3|^5.0
- symfony/dependency-injection: ^4.3|^5.0
- symfony/http-kernel: ^4.3|^5.0
Requires (Dev)
- phpunit/phpunit: ^7.0
- symfony/browser-kit: ^3.4|^4.0
- symfony/framework-bundle: ^3.4|^4.0
- symfony/yaml: ^3.4|^4.0
This package is auto-updated.
Last update: 2024-12-18 21:13:22 UTC
README
a symfony client for phprom, a prometheus metrics datastore for php apps
example
see a fully functional example here
prerequisites
- phprom server
- grpc extension
pecl install grpc
- or use the docker image
related
this is essentially a symfony bundle wrapper for the phprom client
install
with symfony flex
composer require chaseisabelle/phprom-bundle
without symfony flex
- install with composer
composer require chaseisabelle/phprom-bundle
- enable in
app/AppKernel.php
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( ... new ChaseIsabelle\PHPromBundle\ChaseIsabellePHPromBundle(), ); ...
configure
-
create
config/packages/phprom.yaml
phprom: address: 127.0.0.1:3333 # optional, defaults to 127.0.0.1:3333 api: grpc # optional, defaults to grpc (use "rest" for rest api) namespace: my_cool_app # required, the prefix for all your metrics routes: # optional, if empty or omitted then all routes will be recorded - my_cool_route # route can be plain string - only routes matching these strings will be recorded - /^.+$/ # route can be a regex - only routes matching this regex will be recorded
-
open
config/routes.yaml
and addmetrics: resource: '@ChaseIsabellePHPromBundle/Resources/config/routes.xml'
or you can customize
metrics: path: /custom/url/path controller: ChaseIsabelle\PHPromBundle\Controller\MetricsController::metrics
custom metrics
example
src/Controller/DefaultController.php
<?php 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' ]); } }