Remote monitoring with visualvm and JMX

后端 未结 3 1693
太阳男子
太阳男子 2021-01-30 14:20

I would like to monitor a remotely running java (spring boot) application with jvisualvm (or jconsole). When running locally, I can see the managed beans in both jvisualvm and

3条回答
  •  走了就别回头了
    2021-01-30 15:03

    Let me discuss it in detail. I've just connected it to the remote server. U need to go to the folder where your jar file is. Suppose, you want to monitor X.jar file and suppose it is located in usr/local/ folder.. So, first cd into that folder. Then be sure which jdk is running. You can find it by executing command which java in linux. In the command line of the remote server (generally we use PuTTy cmd). In the puTTy cmd write :

    java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.10.0 -jar X.jar
    

    Now let me explain in detail. Here, rmi port is needed to be defined because jmx uses rmi. If we don't define rmi port, it will automatically assign a random port. Then our connection won't be successful. We won't use authentication and ssl because this will cause difficulties. You can try this on your own if you want. In the hostname, you must specify your remote hostname which is the IP address. Now use visualvm located in your local computer. Generally, it can be found in this folder:

    C://Program Files/Java/jdk1.8.0_201/bin 
    

    If not then download it and paste it into the directory. Run visualvm from your local pc. You will see some options like local, remote. In the "remote" option select "Add Remote Host". Add your hostname. In my case, it was 192.168.10.0. Then right-click on your mouse and select "Add jmx connection". A window will open and insert your port number. In my case, it was 9010. You can specify any port number. Select "do not require ssl connection" and don't select the security credentials. Because we've added in the properties that authentication is false. Now connect and your connection will go smoothly. One more suggestion. You can connect using "jstatd connection. But it doesn't work. Doesn't show any output. Maybe because java 8 problems or so. For monitoring memory details you will need an updated version of "visualvm.exe". You can download it. You can connect using Authentication and SSL. The detailed steps using Authentication=true is discussed in this link: Connect to remote JMX Agent with authentication

    The detailed steps using both authentication=true and SSL = true is discussed in this link: JConsole SSL/TLS with Password Authentication

提交回复
热议问题