You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Spring Integration AMQP/JMS通道消息指标暴露给Prometheus

实现步骤

1. 通道兼容性确认

你当前使用的channelMQ_RMQ如果是Spring Integration标准<int:channel>定义的通道,默认实现为DirectChannel,本身继承AbstractMessageChannel,完全符合指标采集要求,无需修改现有通道相关配置。

2. 新增依赖

先引入所需依赖(以Maven为例,Gradle对应调整即可):
如果是Spring Boot项目:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

如果是普通Spring项目,额外引入对应版本的spring-integration-micrometer依赖即可。

3. 新增配置

XML配置(通用)

在现有XML配置中添加以下Bean,无需修改原有业务配置:

<!-- 注册Prometheus计量注册表 -->
<bean id="prometheusMeterRegistry" class="io.micrometer.prometheus.PrometheusMeterRegistry">
    <constructor-arg>
        <bean class="io.micrometer.prometheus.PrometheusConfig" factory-method="DEFAULT"/>
    </constructor-arg>
</bean>

<!-- 注册Spring Integration指标采集器,绑定Prometheus注册表 -->
<bean id="integrationMeterRegistry" class="org.springframework.integration.support.management.micrometer.MicrometerMetricsCaptor">
    <constructor-arg ref="prometheusMeterRegistry"/>
</bean>

<!-- 全局开启Spring Integration指标统计 -->
<bean class="org.springframework.integration.config.EnableIntegrationManagementConfiguration">
    <property name="metricsCaptor" ref="integrationMeterRegistry"/>
    <property name="defaultLoggingEnabled" value="false"/>
</bean>

Spring Boot项目可选配置

如果是Spring Boot项目,上述XML Bean可省略,只需在application.yml添加配置即可:

management:
  endpoints:
    web:
      exposure:
        include: prometheus
  metrics:
    tags:
      application: ${spring.application.name}
spring:
  integration:
    management:
      default-metrics-enabled: true

4. 指标采集验证

服务启动后访问http://{服务地址}/actuator/prometheus,可看到以下核心指标:

  • spring_integration_channel_send_count{name="channelMQ_RMQ"}:通道发送消息总数
  • spring_integration_channel_receive_count{name="channelMQ_RMQ"}:通道接收消息总数
  • spring_integration_channel_error_count{name="channelMQ_RMQ"}:通道处理错误总数
  • 还可查看MQ消息驱动适配器、Rabbit出站适配器的处理耗时、成功率等细分指标

5. Prometheus对接

在Prometheus配置文件中新增抓取任务即可:

scrape_configs:
  - job_name: 'spring-integration-gateway'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['{服务地址}:{端口}']

后续可直接在Prometheus中查询指标,或导入Grafana官方Spring Integration仪表板实现可视化监控。


内容的提问来源于stack exchange,提问作者Marvin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 04:54:02