4

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

在 TestMonitoring application 中,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.xxx: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)

这种异常的原因可能是什么,只是无法弄清楚?任何建议都会非常有帮助

4

1 回答 1

0

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

-javaagent:/opt/agent-bond/agent-bond.jar=/etc/config/agent-bond.properties
于 2019-01-19T14:24:18.807 回答