如何配置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
相关产品推荐
相关产品推荐

