定制 gh05tpl/messenger-prometheus-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gh05tpl/messenger-prometheus-bundle

Composer 安装命令:

composer require gh05tpl/messenger-prometheus-bundle

包简介

Symfony bundle exposing Messenger worker metrics for Prometheus.

README 文档

README

Symfony bundle exposing Messenger worker metrics for Prometheus.

It integrates with artprima/prometheus-metrics-bundle and increments counters when Symfony Messenger workers receive, handle, fail, or retry messages.

Installation

composer require gh05tpl/messenger-prometheus-bundle

If your application does not use Symfony Flex auto-registration, enable both bundles manually:

// config/bundles.php

return [
    Artprima\PrometheusMetricsBundle\ArtprimaPrometheusMetricsBundle::class => ['all' => true],
    Gh05tPL\MessengerPrometheusBundle\Gh05tPLMessengerPrometheusBundle::class => ['all' => true],
];

Configure Prometheus Metrics Bundle

For Messenger worker metrics, use shared storage so the worker process and the HTTP process exposing metrics can see the same counters. Redis is the safest default.

# config/packages/artprima_prometheus_metrics.yaml
artprima_prometheus_metrics:
  namespace: app
  storage:
    type: redis
    host: '%env(default:redis:REDIS_HOST)%'
    port: '%env(int:default:6379:REDIS_PORT)%'
    prefix: app_prometheus

For a quick local smoke test only, you can use in-memory storage:

# config/packages/artprima_prometheus_metrics.yaml
artprima_prometheus_metrics:
  namespace: app
  storage:
    type: in_memory

In-memory storage is not recommended for real Messenger worker metrics because workers and web requests usually run in different PHP processes.

Expose Metrics Endpoint

Import the route provided by artprima/prometheus-metrics-bundle:

# config/routes/prometheus.yaml
prometheus_metrics:
  resource: '@ArtprimaPrometheusMetricsBundle/Resources/config/routing.yaml'

The endpoint is available at:

/metrics/prometheus

Point Prometheus at that endpoint, for example:

scrape_configs:
  - job_name: symfony
    metrics_path: /metrics/prometheus
    static_configs:
      - targets:
          - app.example.com

Run Messenger Workers

No extra code is required. Once the bundle is enabled, it subscribes to Symfony Messenger worker events automatically.

php bin/console messenger:consume async -vv

The bundle records these counters:

app_messenger_worker_messages_total{event,message_class,receiver_name}
app_messenger_worker_failures_total{message_class,receiver_name,exception_class,will_retry}

The event label can be one of:

received
handled
failed
retried

The metric prefix comes from artprima_prometheus_metrics.namespace. If you set namespace: my_app, the counters will be named:

my_app_messenger_worker_messages_total
my_app_messenger_worker_failures_total

Development

This repository includes a Docker-based development environment.

make build
make install
make test
make validate

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固