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

如何配置Prometheus JMX Exporter仅暴露ActiveMQ指定Topic指标?

问题场景

我正在运行AMQ并使用jmx_exporter,采用如下YAML配置文件:

lowercaseOutputName: true
lowercaseOutputLabelNames: true
blacklistObjectNames:
  - "org.apache.activemq:clientId=*,*"
whitelistObjectNames:
  - "org.apache.activemq:destinationType=Topic,*"

rules:

  - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
    name: activemq_topic_$3
    attrNameSnakeCase: true
    labels:
      destination: $2

当前得到的输出示例如下:

activemq_topic_enqueue_count{destination="topic_1_name",} 0.0

问题

目前端点会暴露所有属性,但我仅关注enqueue_count和dequeue_count这两个指标,请问该如何实现?

解决方案

要只保留指定的两个指标,有两种简单可行的修改方式:

方式一:精确匹配属性的正则规则

修改原规则中的正则匹配部分,把原本匹配任意属性的(\w+)替换为仅匹配enqueue_count和dequeue_count的表达式,这样只会生成这两个指标。修改后的配置如下:

lowercaseOutputName: true
lowercaseOutputLabelNames: true
blacklistObjectNames:
  - "org.apache.activemq:clientId=*,*"
whitelistObjectNames:
  - "org.apache.activemq:destinationType=Topic,*"

rules:

  - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(enqueue_count|dequeue_count)
    name: activemq_topic_$3
    attrNameSnakeCase: true
    labels:
      destination: $2

方式二:添加属性白名单过滤

在原规则中新增whitelistAttributes字段,指定只保留需要的JMX原始属性名(注意这里要用JMX里的驼峰命名形式,比如EnqueueCount,attrNameSnakeCase会自动转成下划线格式的指标名)。修改后的配置如下:

lowercaseOutputName: true
lowercaseOutputLabelNames: true
blacklistObjectNames:
  - "org.apache.activemq:clientId=*,*"
whitelistObjectNames:
  - "org.apache.activemq:destinationType=Topic,*"

rules:

  - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
    name: activemq_topic_$3
    attrNameSnakeCase: true
    labels:
      destination: $2
    whitelistAttributes:
      - "EnqueueCount"
      - "DequeueCount"

两种方式都能实现需求,第二种方式更易维护,后续调整关注的属性时,直接修改白名单列表即可,无需改动正则表达式。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 16:35:10