Download the PHP package artprima/prometheus-metrics-bundle without Composer
On this page you can find all versions of the php package artprima/prometheus-metrics-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download artprima/prometheus-metrics-bundle
More information about artprima/prometheus-metrics-bundle
Files in artprima/prometheus-metrics-bundle
Package prometheus-metrics-bundle
Short Description Symfony 5 / 6 Prometheus Metrics Bundle
License MIT
Informations about the package prometheus-metrics-bundle
Master |
---|
Symfony 5/6/7 Prometheus Metrics Bundle
A Symfony bundle for the promphp/prometheus_client_php
.
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
Configuration
config.yaml
Supported types are: | Adapter name | Prometheus class |
---|---|---|
in_memory | Prometheus\Storage\InMemory | |
apcu | Prometheus\Storage\APC | |
apcng | Prometheus\Storage\APCng | |
redis | Prometheus\Storage\Redis |
routes.yaml
You can alternatively define your own path and rules:
Now your metrics are available to Prometheus using http://
Custom Metrics Collector
If you want to collect your own metrics, you should create a class that will implement one or several interfaces that are
the children of the Artprima\PrometheusMetricsBundle\Metrics\MetricsCollectorInterface
.
When using autoconfigure = true, by implementing Artprima\PrometheusMetricsBundle\Metrics\MetricsCollectorInterface
Symfony will automatically configure your metrics collector to be used by the collector registry.
By implementing one of the following interfaces you can collect the metrics on one of the listed Symfony kernel events:
Artprima\PrometheusMetricsBundle\Metrics\PreRequestMetricsCollectorInterface
- collect metrics on "kernel.request" event with a priority of 1024.
Artprima\PrometheusMetricsBundle\Metrics\RequestMetricsCollectorInterface
- collect metrics on "kernel.request" event (default priority).
Artprima\PrometheusMetricsBundle\Metrics\PreExceptionMetricsCollectorInterface
- collect metrics on "kernel.exception" event with a priority of 1024.
Artprima\PrometheusMetricsBundle\Metrics\ExceptionMetricsCollectorInterface
- collect metrics on "kernel.exception" event with (default priority).
Artprima\PrometheusMetricsBundle\Metrics\TerminateMetricsCollectorInterface
- collect metrics on "kernel.terminate" event.
The following collectors will only work if you define enable_console_metrics: true
in the bundle configuration:
Artprima\PrometheusMetricsBundle\Metrics\ConsoleCommandMetricsCollectorInterface
- collect metrics on "console.command" event.
Artprima\PrometheusMetricsBundle\Metrics\ConsoleTerminateMetricsCollectorInterface
- collect metrics on "console.terminate" event.
Artprima\PrometheusMetricsBundle\Metrics\ConsoleErrorMetricsCollectorInterface
- collect metrics on "console.error" event.
For advanced usage you can implement Artprima\PrometheusMetricsBundle\Metrics\MetricsCollectorInterface
directly.
There is also Artprima\PrometheusMetricsBundle\Metrics\MetricsCollectorInitTrait
will add the init
method to your
collector.
If you don't use autoconfigure = true, then you will have to add this to your services.yaml
:
Custom Storage Adapter Factory
A storage adapter is an instance of Prometheus\Storage\Adapter
.
To create your own storage adapter you should create a custom factory implementing Artprima\PrometheusMetricsBundle\StorageFactory\StorageFactoryInterface
.
Symfony will automatically configure your storage factory with autoconfigure = true and implementing Artprima\PrometheusMetricsBundle\StorageFactory\StorageFactoryInterface
.
If you don't use autoconfigure = true, then you will have to add this to your services.yaml
:
Default Metrics
These are default metrics exported by the application:
Note that, php_info comes from the underlying library promphp/prometheus_client_php
. Other metrics are gathered
by the built-in class Artprima\PrometheusMetricsBundle\Metrics
. Here, in the example we have a prefix symfony
and the metrics show a single request to the root named app_dummy_homepage
. Symfony instance is named dev
here.
Instance name comes from the server var HOSTNAME
($request->server->get('HOSTNAME')
) and defaults to dev
.
Clear Metrics
The bundle provides a console command to clear metrics from the storage. Simply run:
Contributors
denisvmedia | Johnmeurt | rmbl | InboxViktorV | jb-reynaud | luca-nardelli |
alshenetsky | edditor | marein | ctrl-f5 | ns3777k | scrutinizer-auto-fixer |
Yozhef | karolmalinowski |
Code license
You are free to use the code in this repository under the terms of the MIT license. LICENSE contains a copy of this license.
All versions of prometheus-metrics-bundle with dependencies
ext-json Version *
promphp/prometheus_client_php Version ^2.6
symfony/http-kernel Version ^5.4|^6.2|^7.0
symfony/dependency-injection Version ^5.4|^6.2|^7.0
symfony/config Version ^5.4|^6.2|^7.0