Skip to content

Bridge between Symfony/Messenger & M6Web/StatsdPrometheusBundle🔗

In this cookbook you will find how to monitor your messenger async queue using the StatsdTagsPrometheusBundle.

Installation🔗

1
composer require symfony/messenger m6web/statsd-prometheus-bundle

Stamps for Messenger🔗

  • MetricReceivedAtStamp: contains the received date of the message (this information change each time the event is retried)
  • MetricSentAtStamp: contains the send date of the message

Events for the StatsdPrometheusBundle🔗

This component provides a bunch of events to track the Symfony Messenger health

MessageReceivedEvent🔗

When a message is received by the worker we can retrieve the elapsed time

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
App\Infra\Bridge\Symfony\Messenger\Metric\Event\MessageReceivedEvent:
    flush_metrics_queue: true
    metrics:
        - type: 'increment'
          name: 'messenger_event_received_total'
          tags:
              class: ~
              receiver: ~
        - type: 'timer'
          name: 'messenger_event_received_elapsed_time_seconds'
          param_value: 'elapsed_time'
          tags:
              class: ~
              receiver: ~

MessageHandledEvent🔗

When a message is successfully handled by the worker

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
App\Infra\Bridge\Symfony\Messenger\Metric\Event\MessageHandledEvent:
    flush_metrics_queue: true
    metrics:
        - type: 'increment'
          name: 'messenger_event_handled_total'
          tags:
              class: ~
              receiver: ~
        - type: 'timer'
          name: 'messenger_event_handled_elapsed_time_seconds'
          param_value: 'elapsed_time'
          tags:
              class: ~
              receiver: ~
        - type: 'timer'
          name: 'messenger_event_handled_seconds'
          param_value: 'duration'
          tags:
              class: ~
              receiver: ~

MessageFailedEvent🔗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
App\Infra\Bridge\Symfony\Messenger\Metric\Event\MessageFailedEvent:
    flush_metrics_queue: true
    metrics:
        - type: 'increment'
          name: 'messenger_event_failed_total'
          tags:
              class: ~
              receiver: ~
        - type: 'timer'
          name: 'messenger_event_failed_seconds'
          param_value: 'duration'
          tags:
              class: ~
              receiver: ~

MessageRetriedEvent🔗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
App\Infra\Bridge\Symfony\Messenger\Metric\Event\MessageRetriedEvent:
    flush_metrics_queue: true
    metrics:
        - type: 'increment'
          name: 'messenger_event_retried_total'
          tags:
              class: ~
              receiver: ~
        - type: 'timer'
          name: 'messenger_event_retried_seconds'
          param_value: 'duration'
          tags:
              class: ~
              receiver: ~

QueueMetricEvent🔗

This event sends statistics about the queue usages (how many events are waiting per transport).
The provided QueueMetricEventSubscriber sends these stats only whenever the worker starts/stops in order to reduce I/O, so you might not get accurate metrics depending on your volumes & nb of simultaneous workers running. Adapt to your needs (you could create your own subscriber sending these informations on each received message instead).

1
2
3
4
5
6
7
8
App\Infra\Bridge\Symfony\Messenger\Metric\Event\QueueMetricEvent:
    flush_metrics_queue: true
    metrics:
        - type: 'gauge'
          name: 'messenger_queue_message_count'
          param_value: 'count'
          tags:
              receiver: ~

To choose which transports to monitor, you'll need to define the following parameter with your transport names:

1
2
3
4
5
6
parameters:
    metrics.messenger.receivers_to_inspect:
        - async
        - async_low
        - notifications
        - failed_events

Last update: December 20, 2024