Download the PHP package tasko-products/symfony-prometheus-exporter without Composer
On this page you can find all versions of the php package tasko-products/symfony-prometheus-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tasko-products/symfony-prometheus-exporter
More information about tasko-products/symfony-prometheus-exporter
Files in tasko-products/symfony-prometheus-exporter
Package symfony-prometheus-exporter
Short Description Generic metrics exporter for Symfony including messenger event metrics via middleware, request metrics, logging metrics and custom metrics via the Collector composition
License MIT
Homepage https://www.tasko.de/
Informations about the package symfony-prometheus-exporter
Symfony Prometheus Exporter
Please note that this package is under active development. There may still be occasional errors when collecting metrics.
Please report bugs as an issue in Github (new issue) or send us a pull request
The Symfony Prometheus Exporter is a bundle that includes a bunch of generic Prometheus metrics for your Symfony application, stored in your Redis repository.
Each metric collector can be enabled and disabled separately, so you can decide for your app which data to collect and provide to the Prometheus query.
- messenger metrics via middleware
- messenger metrics via events
- (todo) request metrics
- (todo) logging metrics
- (todo) custom metrics via the Collector composition
This Symfony bundle is based on the unoffical Prometheus PHP client PHP library.
Messenger metrics via middleware
The counters will be incremented when a message is dispatched, as well as when it is received from a worker.
Middleware | Description | Metric |
---|---|---|
MessengerEventMiddleware | This middleware increases a counter for every step a message makes. | Counter |
RetryMessengerEventMiddleware | This middleware increases a counter for every step a retry message makes. | Counter |
Messenger metrics via events
Subscriber | Events | Description | Metric |
---|---|---|---|
ActiveWorkersMetricEventSubscriber | WorkerStartedEvent, WorkerStoppedEvent | This subscriber keeps track of currently active workers. | Gauge |
MessagesInProcessMetricEventSubscriber | WorkerMessageReceivedEvent, WorkerMessageHandledEvent, WorkerMessageFailedEvent | This subscriber keeps track of messages that are currently being processed. | Gauge |
MessagesInTransportMetricEventSubscriber | SendMessageToTransportsEvent, WorkerMessageReceivedEvent | This subscriber keeps track of messages that are currently being transfered. | Gauge |
Installation for applications that use Symfony Flex
Open a command console, enter your project directory and execute:
Installation for applications that don't use Symfony Flex
Step 1: Download SymfonyPrometheusExporter using composer
Require the tasko-products/symfony-prometheus-exporter
with composer Composer.
Step 2: Enable the bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Configuration
Open metrics route (optional)
1. Register the route
Add the following yaml to your routes config to register the open_metrics
route.
2. Secure the route with basic authentication
Please use only basic authentication if you communicate with your application via TLS, or locally for development purposes. Your password is only base64 encoded.
To secure your routes you need the Symfony Security Bundle. Make sure it is installed by running:
Next you define a password hasher, if none has been defined yet. Again, make sure it is installed by running:
Then add it to your security config.
Generate an encoded password.
Symfony version < 6:
Symfony version >= 6:
Store the encoded password and the username in your environments file.
Add Symfony's memory user provider to the security providers. Here you use the environment variables you defined before.
Finally, you need a firewall to secure your route. Add the following http_basic firewall to your security config.
Try to retrieve your metrics with the following curl and set the Authorization
header to your secrets.
Encode your secrets on Linux and Mac:
On Windows use Certutil to encode your secrets as base64.
Prometheus Redis configuration (optional)
Add the Prometheus
Redis configuration to your services.
By default, the bundle comes with an in-memory configuration:
Enable the symfony/messenger middleware metrics collector (optional)
Register the desired middlewares for your message bus(es).
To overwrite the default labels and texts:
Please note that changes to metric names are only valid if they match the following regular expression:
/^[a-zA-Z_:][a-zA-Z0-9_:]*$/
Validate your name on regex101.com
Create a new yaml configuration file
app/config/packages/prometheus_metrics.yaml
if it does not already exist. Add the following
configuration and now you can adjust the labels and texts via the following configuration.
Example for the MessengerEventMiddleware
:
Example for the RetryMessengerEventMiddleware
:
Enable the messager event subscriber metric collectors (optional)
Please note that changes to metric names are only valid if they match the following regular expression:
/^[a-zA-Z_:][a-zA-Z0-9_:]*$/
Validate your name on regex101.com
Register the desired event subscribers as necessary. Create a new configuration yaml file
app/config/packages/prometheus_metrics.yaml
. Add the following configuration and now you can activate/
deactivate the event subscribers and adjust the labels and texts via the following configuration.
Example for the active_workers (ActiveWorkersMetricEventSubscriber
):
Example for the messages_in_process (MessagesInProcessMetricEventSubscriber
):
Example for the messages_in_transport (MessagesInTransportMetricEventSubscriber
):
Testing
PHPUnit
Install dependencies:
Run the tests:
PHPUnit via docker-compose
Just start the nginx, fpm & Redis setup with docker-compose:
Then run phpunit with docker-compose::
Static code analysis
PHPStan
Install dependencies:
And just run the analysis:
Code cleanup
php-cs-fixer
Install dependencies:
And just run the cleanup:
Copyright (c) 2022 tasko Products GmbH 2022. MIT licence.
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
All versions of symfony-prometheus-exporter with dependencies
symfony/framework-bundle Version ^5.4 || ^6.0 || ^7.0
promphp/prometheus_client_php Version ^2.12.0
symfony/messenger Version ^5.4 || ^6.0 || ^7.0
tasko-products/php-codestyle Version ^1.0.0