Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fjogeleit/prometheus-messenger-middleware
Symfony Messenger Middleware for Prometheus Monitoring
https://github.com/fjogeleit/prometheus-messenger-middleware
cqrs prometheus symfony symfony-messenger
Last synced: 19 days ago
JSON representation
Symfony Messenger Middleware for Prometheus Monitoring
- Host: GitHub
- URL: https://github.com/fjogeleit/prometheus-messenger-middleware
- Owner: fjogeleit
- License: mit
- Created: 2020-07-26T17:03:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-03T16:17:46.000Z (10 months ago)
- Last Synced: 2024-10-12T06:21:07.428Z (about 1 month ago)
- Topics: cqrs, prometheus, symfony, symfony-messenger
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 20
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Prometheus Messenger Middleware
![CodeStyle](https://github.com/fjogeleit/prometheus-messenger-middleware/workflows/CodeStyle/badge.svg)
A Simple Middleware to Monitor your Symfony Messenger Component with two Prometheus Counter Metrics per MessageBus.
* Counter overall executed Messages
* Counter failed Messages## Dependencies
* PHP >= 7.2.5
* promphp/prometheus_client_php
* symfony/messenger## Installation
```bash
composer require fjogeleit/prometheus-messenger-middleware
```## Usage
Configure this Middleware to your MessageBus
### Symfony Basic Example
#### Register your Services
```yaml
services:
Prometheus\Storage\InMemory: ~
Prometheus\CollectorRegistry: ['@Prometheus\Storage\InMemory']PrometheusMiddleware\PrometheusMiddleware: ~
```#### Configure Middleware
```yaml
framework:
messenger:
buses:
message.bus.commands:
middleware:
- 'PrometheusMiddleware\PrometheusMiddleware'
```Generated Example Counter Response with the default Labels "message" as full qualified MessageName and "label" as Message ClassName
```text
# HELP message_bus_commands_messenger Executed Messages
# TYPE message_bus_commands_messenger counter
message_bus_commands_messenger{message="PrometheusMiddleware\\\\Tests\\\\Example\\\\FooMessage",label="FooMessage"} 2
message_bus_commands_messenger{message="PrometheusMiddleware\\\\Tests\\\\Example\\\\FooMessage",label="BarMessage"} 1
```
## Advanced UsageYou can also configure your own Labels and provide the related Values
### Configure your own labels as additional service argument
```yaml
services:
...PrometheusMiddleware\PrometheusMiddleware:
arguments:
$labels: ['message', 'label','value']
```### Create a LabelValueProvider
Create your own LabelValueProvider by implementing the `LabelValueProviderInterface`
```php
getMessage();return [
\get_class($message),
substr(strrchr(get_class($message), '\\'), 1),
$message->getBar()
];
}
}
```
Add your new LabelValueProvider to your ServiceConfiguration```yaml
services:
...
PrometheusMiddleware\Tests\Example\FooLabelValueProvider: ~PrometheusMiddleware\PrometheusMiddleware:
arguments:
$labels: ['message', 'label','value']
$labelValueProvider: '@PrometheusMiddleware\Tests\Example\FooLabelValueProvider'
```
You can also provide custom labels for the ErrorCounter with the `ErrorLabelValueProviderInterface````php
getMessage();return [
\get_class($message),
substr(strrchr(get_class($message), '\\'), 1),
$exception->getMessage()
];
}
}
```
And the updated ServiceConfiguration```yaml
services:
...
PrometheusMiddleware\Tests\Example\FooExceptionLabelValueProvider: ~PrometheusMiddleware\PrometheusMiddleware:
arguments:
$errorLabels: ['message', 'label','value']
$errorLabelValueProvider: '@PrometheusMiddleware\Tests\Example\LabelValueProvider'
```## Full PrometheusMiddleware API
| Property | Required | Description
|---------------------------------|------------------|-------------------------------------------------------------------|
| CollectorRegistry $collectorRegistry | required | Underlying CollectorRegistry to generate and persist your metrics |
| string $metricName | optional | Default `message`, used as "name" for your `Counter` |
| string $helpText | optional | Default `Executed Messages`, used as `Counter` help text |
| array $labels | optional | Default `['message', 'label']`, default provided `Counter` labels |
| LabelValueProviderInterface $provider | optional | Default `DefaultLabelValueProvider`, provides the `Counter` label related values |
| string $errorHelpText | optional | Default `Failed Messages`, used as Error `Counter` help text |
| array $errorLabels | optional | Default `['message', 'label']`, default provided Error `Counter` labels |
| ErrorLabelValueProviderInterface $errorLabelValueProvider | optional | Default `DefaultErrorLabelValueProvider`, provides the Error `Counter` label related values |