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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-prometheus-exporter

Symfony Prometheus Exporter

Code Checks Tests

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.

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

PHP Build Version
Package Version
Requires php Version >=8.1
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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tasko-products/symfony-prometheus-exporter contains the following files

Loading the files please wait ....