How to access JMX interface in docker from outside?

前端 未结 5 1129
情深已故
情深已故 2020-12-02 07:54

I am trying to remotely monitor a JVM running in docker. The configuration looks like this:

  • machine 1: runs a JVM (in my case, running kafka) in docker on

5条回答
  •  醉话见心
    2020-12-02 08:27

    I found it that trying to set up JMX over RMI is a pain, especially because of the -Djava.rmi.server.hostname= which you have to specify on startup. We're running our docker images in Kubernetes where everything is dynamic.

    I ended up using JMXMP instead of RMI, as this only need one TCP port open, and no hostname.

    My current project uses Spring, which can be configured by adding this:

    
    

    (Outside Spring you need to set up your own JMXConncetorServer in order to make this work)

    Along with this dependency (since JMXMP is an optional extension and not a part of the JDK):

    
        org.glassfish.main.external
        jmxremote_optional-repackaged
        4.1.1
    
    

    And you need to add the same jar your your classpath when starting JVisualVM in order to connect over JMXMP:

    jvisualvm -cp "$JAVA_HOME/lib/tools.jar:/jmxremote_optional-repackaged-4.1.1.jar"
    

    Then connect with the following connection string:

    service:jmx:jmxmp://
    

    (Default port is 9875)

提交回复
热议问题