使用JMX_Exporter监控MBean无数据返回,求排查建议
问题
使用JMX_Exporter监控应用暴露的MBean,目标MBean的ObjectName为com.production.swee.cis:name=CircuitBreaker,需要监控的属性包括:
- CircuitTripped
- FailureCount
- FailureEntries
- FailureEntryTimeout
- FailureLimit
先后尝试两种配置均未获取到指标数据,第一种配置如下:
lowercaseOutputLabelNames: true lowercaseOutputName: true whitelistObjectNames: - "--other ObjectNames --" - "com.production.swee.cis:Name=CircuitBreaker" rules: --other rules-- - pattern: 'com.production.swee.cis<Name=CircuitBreaker><>(\w+):' name: jmx_circuitbreaker labels: name: "$1" help: jmx_CircuitBreaker_status type: GAUGE
第二种尝试的配置:
lowercaseOutputLabelNames: true lowercaseOutputName: true whitelistObjectNames: - "--other ObjectNames --" - "com.production.swee.cis:Name=CircuitBreaker" rules: --other rules-- - pattern: '(.*)' name: jmx_circuitbreaker labels: name: "$1" help: jmx_CircuitBreaker_status type: GAUGE
怀疑是whitelistObjectNames或匹配模式不匹配导致指标无返回,求排查思路。
排查思路
1. 先确认MBean的真实性与可访问性
- 用
jconsole或jvisualvm连接目标JVM,在MBean浏览器中查找com.production.swee.cis:name=CircuitBreaker,确认该MBean存在,且要监控的5个属性能正常读取到值。 - 注意JMX的ObjectName大小写敏感:目标MBean是
name=CircuitBreaker(小写name),但配置里的whitelistObjectNames写的是Name=CircuitBreaker(大写Name),这是高频错误,先把白名单里的Name改成小写name测试。
2. 修正正则匹配模式
- 第一种配置里的pattern用了
<和>这类HTML转义字符,JMX_Exporter的正则不需要转义,正确格式应使用JMX标准的ObjectName结构匹配,比如:
或者精准匹配目标属性,避免无关属性被采集:- pattern: 'com.production.swee.cis:name=CircuitBreaker,(\w+):' name: jmx_circuitbreaker labels: attribute: "$1" help: "CircuitBreaker attribute $1" type: GAUGE- pattern: 'com.production.swee.cis:name=CircuitBreaker,(CircuitTripped|FailureCount|FailureEntries|FailureEntryTimeout|FailureLimit):' name: jmx_circuitbreaker_$1 help: "CircuitBreaker $1 value" type: GAUGE
3. 排查白名单的规则冲突
- 暂时注释掉
whitelistObjectNames里的其他条目,只保留目标MBean的规则,测试是否能获取指标——避免其他通配符或错误规则干扰匹配。 - 检查白名单里的每个条目是否符合ObjectName语法,没有多余符号或拼写错误。
4. 启用调试日志定位问题
- 启动JMX_Exporter时添加日志参数
-Dlogging.level.io.prometheus.jmx=DEBUG,查看日志中是否有MBean匹配失败、属性读取错误、权限不足等提示,直接定位问题点。
5. 用极简配置做测试
- 去掉所有无关规则和白名单条目,用最简化的配置验证:
确认能获取指标后,再逐步添加原有规则排查冲突。lowercaseOutputLabelNames: true lowercaseOutputName: true whitelistObjectNames: - "com.production.swee.cis:name=CircuitBreaker" rules: - pattern: 'com.production.swee.cis:name=CircuitBreaker,(\w+):' name: jmx_circuitbreaker labels: attr: "$1" help: "CircuitBreaker attribute" type: GAUGE
内容的提问来源于stack exchange,提问作者olti
相关产品推荐
相关产品推荐

