如何配置JMX导出器以监视Prometheus中的弹簧启动应用程序

时间:2017-09-22 13:16:25

标签: jmx prometheus spring-jmx

使用JMX导出器和Prometheus监控Spring启动应用程序(TestMonitoring)。 Prometheus和spring boot应用程序Pod已在kubernetes集群中启动并运行。 现在的痛苦是让JMX导出器运行,应用程序应该通过JMX公开指标。

在TestMonitoring应用程序中,application.properties文件具有以下设置:

endpoints.jmx.enabled=true
spring.jmx.enabled=true

现在如何将JMX导出器安装为代理: 我已下载jar并执行:

java -javaagent:./jmx_prometheus_javaagent-0.9.jar=1234:config.yml

在config.yml中 - >以下hostPort:xx.x.x.x:30001(myspring启动应用程序的目标端口,可作为服务提供)

抛出以下异常:

Sep 22, 2017 4:12:31 PM 

io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector collect
SEVERE: JMX scrape failed: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [R              oot exception is java.rmi.ConnectIOException: non-JRMP server at remote endpoint]
        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:370)
        at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:268)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxScraper.doScrape(JmxScraper.java:106)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector.collect(JmxCollector.java:401)
        at io.prometheus.jmx.shaded.io.prometheus.client.CollectorRegistry.collectorNames(CollectorRegistry.java:99)
        at io.prometheus.jmx.shaded.io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:50)
        at io.prometheus.jmx.shaded.io.prometheus.client.Collector.register(Collector.java:128)
        at io.prometheus.jmx.shaded.io.prometheus.client.Collector.register(Collector.java:121)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: non-JRMP server at remote               endpoint]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:142)
        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:204)
        at javax.naming.InitialContext.lookup(InitialContext.java:415)
        at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1928)
        at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1895)
        at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)

这种例外可能是什么原因,只是不能算出来?任何建议都会非常有用

1 个答案:

答案 0 :(得分:0)

尝试https://github.com/fabric8io/agent-bond
工作正常。 像这样使用它:

-javaagent:/opt/agent-bond/agent-bond.jar=/etc/config/agent-bond.properties