How to connect JMC (Java Mission Control) to remote JVM in ubuntu?
Asked Answered
T

4

25

I am able to connect to JMC to the JVM while on the same system. However, I want to monitor a remote server. How do I connect my local JMC to my remote JVM?

Todhunter answered 27/2, 2015 at 12:28 Comment(0)
O
-8

In the server {Ubuntu} Edit the /etc/hosts file

127.0.1.1       server-name

Replace above line with this line

<system-ip>     server-name
Option answered 3/3, 2015 at 13:42 Comment(1)
The other answer provided by hirt is much more usefulEpigraphy
S
58

It's all described in the documentation:
1. Click Help->Java Mission Control Help.
2. Check the JVM browser help.

For more detailed information, check out:
http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html

First you need to enable the external JMX agent on the server. You do this by adding the relevant com.sun.management.jmxremote to the command line flags for the server JVM you wish to connect to. Here is a simple example of a set of system properties that can be used. They disable security and authentication, so NEVER use it like this in production:

-Dcom.sun.management.jmxremote.port=7091
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

Next you create a custom connection in JMC. You do this by clicking the "Create custom connection" button in the JVM browser: Location of create custom connection button

In the upcoming dialog you simply enter the host and port.

If you run into trouble, first check the last chapter of the documentation included with JMC (Frequently Asked Questions): Where to Find the Help

If that does not help, the JMC Forum has a more extensive FAQ: https://community.oracle.com/message/11182417#11182417.

Southworth answered 28/2, 2015 at 10:8 Comment(4)
btw if connection still isn't established - try adding the following Java system property -Djava.rmi.server.hostname=<ip>Fere
Yep. That is listed as one of the things to try in the included documentation (last chapter - Frequently Asked Questions). I should probably also link to the FAQ in the forum: community.oracle.com/message/11182417#11182417 Will add it to my answer.Southworth
In case of SSH-tunnelling, -Djava.rmi.server.hostname=localhost and -Dcom.sun.management.jmxremote.rmi.port=[...] is needed to let the client access remote RMI-objects through the tunnel using a known port instead of a random one.Powe
Nice article here that explains how to do the SSH tunneling issamben.com/how-to-monitor-remote-jvm-over-ssh. This worked for me since I couldn't directly connect to my remote process.Dearborn
V
12

My environment is jboss 7.1 in Linux, was trying to connect JMC to my jboss instance, initially I got problems with connection refused - after a day and half of digging, remote JMC works for me now, with the following configs in standalone.conf:

JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager"

JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS"


JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager"

JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/apps/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/main/jboss-logmanager-1.2.2.GA.jar"
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/apps/jboss-as-7.1.1.Final/modules/org/jboss/logmanager/log4j/main/jboss-logmanager-log4j-1.0.0.GA.jar"
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/p:/apps/jboss-as-7.1.1.Final/modules/org/apache/log4j/main/log4j-1.2.16.jar"

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=7091"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=7091"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"

JAVA_OPTS="$JAVA_OPTS -XX:+UnlockCommercialFeatures"
JAVA_OPTS="$JAVA_OPTS -XX:+FlightRecorder"
Vowelize answered 15/7, 2016 at 13:43 Comment(1)
I would like to put special attention on -Dcom.sun.management.jmxremote.rmi.port=[...] which is needed in case of firewalls, SSH-tunnelling etc., because without it random ports are used by RMI to provide remote objects which clients need to access. -Djava.rmi.server.hostname=[...] might be necessary as well.Powe
R
2

I was able to see a JVM within VirtualBox (Host: Win10, Guest: Ubuntu 20.04) after running the target JVM with following flags:

java -XX:+FlightRecorder \
-Dcom.sun.management.jmxremote.port=1101 \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
MyApp
Revolve answered 23/11, 2021 at 21:9 Comment(0)
O
-8

In the server {Ubuntu} Edit the /etc/hosts file

127.0.1.1       server-name

Replace above line with this line

<system-ip>     server-name
Option answered 3/3, 2015 at 13:42 Comment(1)
The other answer provided by hirt is much more usefulEpigraphy

© 2022 - 2024 — McMap. All rights reserved.