无法使用kafka.tools.JmxTool获取JMX指标

时间:2019-02-11 10:53:23

标签: java apache-kafka jmx jconsole

我无法使用bin / kafka-run-class.sh kafka.tools.JmxTool脚本获取JMX指标。但是,我可以使用Jconsole连接到进程。

我设置了以下属性:

com.sun.management.jmxremote = true
com.sun.management.jmxremote.authenticate = false
com.sun.management.jmxremote.local.only = false
com.sun.management.jmxremote.port = 9145
com.sun.management.jmxremote.ssl = false

例外:

? kafka_2.11-2.1.0/bin/kafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://kafkatest-01:9154/jmxrmi    
Trying to connect to JMX url: service:jmx:rmi:///jndi/rmi://kafkatest-01:9154/jmxrmi.
Could not connect to JMX url: service:jmx:rmi:///jndi/rmi://kafkatest-01:9154/jmxrmi. Exception Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: kafkatest-01; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)].
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: kafkatest-01; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
    at kafka.tools.JmxTool$.main(JmxTool.scala:120)
    at kafka.tools.JmxTool.main(JmxTool.scala)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: kafkatest-01; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:136)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1922)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
    ... 3 more

1 个答案:

答案 0 :(得分:1)

Trying to connect to JMX url: service:jmx:rmi:///jndi/rmi://kafkatest-01:9154/jmxrmi.

但是您的端口是9145

com.sun.management.jmxremote.port = 9145

想知道正在运行的JVM上实际上设置了哪些属性(用于检查类似这样的东西)

prompt> jcmd $pid VM.system_properties