How to connect Spring Boot application remotely in Visual VM? - java

I am new to Visual VM, how to connect to Spring Boot application remotely in Visual VM?
Multiple instances are running as a java -jar app.jar with random ports. How to connect from Visual VM, I have root access to the remote system. Do I need to enable any security configuration?
In the local system, applications shows up automatically but when I entered remote system IP address it's prompting Add JMX connection and Add jstatd connection.

We need to specify the remote IP ADDRESS and expose the listening PORT while running the jar.
Syntax:
java
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=<PORT>
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=<IP_ADDRESS>
-Dcom.sun.management.jmxremote.rmi.port=<PORT>
-jar app-1.0.0-SNAPSHOT.jar
Example: Listening port is 6001 and available for remote ip address 192.168.0.23
java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=6001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.0.23 -Dcom.sun.management.jmxremote.rmi.port=6001 -jar app-1.0.0-SNAPSHOT.jar
For More details about set up Visual VM https://github.com/M-Thirumal/installation_guide/blob/master/visualVm/visualvm_remote_set_up.md

I encountered this dilemma with Spring Boot as well. But I was not using a jar. I passed the jmx arguments to maven to profile the application without having to build a jar first.
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"
For more details, I documented my steps here.

Related

Mesos java Application Monitoring

I am running a java application on Mesos and Marathon. How do i monitor the heap stats of the java process? I tried jstat which complains "pid not found", but the process is running and i can check it by 'ps auwx'. Is this because the java process is running inside a cgroup? If that is the case how do we monitor mesos based applications.
The best option to monitor application is to publish it's metrics from itself. There are plenty of ways to add monitoring to your application starting from proprietarty such as NewRelic or DataDog to opensource Prometheus.
If you need to get acces via JMX you can expose this port with following configuration:
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=$PORT1 \
-Djava.rmi.server.hostname=$MESOS_HOSTNAME
Above configuration assume you have two ports and second is dedicated for JMX

Using VisualVM on tomcat 8 running on EC2

I am trying to use VisualVM in my system to monitor a Tomcat instance running over EC2. I tried steps provided in multiple blogs about how to configure it, but still when I try to run tomcat it gives me following error.
./catalina.sh: 5: /home/gvr/apache-tomcat-8.0.18/bin/setenv.sh: -Dcom.sun.management.jmxremote: not found
I added following statement in server.xml
<listener classname="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
rmiregistryportplatform="10001"
rmiserverportplatform="10002"
uselocalports="true" />
And my setenv.sh is as follows
CATALINA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=ec2-xx-xxx-xx-xx.ap-southeast-1.compute.amazonaws.com"
$CATALINA_OPTS
Besides this I have added, catalina-jmx-remote.jar in tomcat's lib directory
Could anyone please provide me some hint, what is possibly going wrong. I tried everything I have found related to configuring VisualVM
I am running Tomcat 8.0.18, java 8 over ubuntu
I believe there are two issues
formatting in setenv.sh, you need \ to split across lines
last line $CATALINA_OPTS which tries to execute the arguments, hence -Dcom.sun.management.jmxremote not found...
Suggested fix
CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=ec2-xx-xxx-xx-xx.ap-southeast-1.compute.amazonaws.com"
echo $CATALINA_OPTS
I also tried using the JmxRemoteLifecycleListener and it didn't work for me.
Here it is how I did it:
1)I choose 1005 as jmx port and my setenve.sh is like:
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10005 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost"
2) redirect using ssh the jmx port and the rmi
3) Run visualvm using the following uri: service:jmx:rmi:///jndi/rmi://localhost:10005/jmxrmi
If you need more information have a look to this post:
http://ignaciosuay.com/how-to-connect-a-java-profiler-like-visualvm-or-jconsole-to-a-remote-tomcat-running-on-amazon-ec2/

How to enable the JMX of cluster servers on Weblogic?(not the Weblogic AdminServer itself)

I am running Weblogic 12c on CentOS6. I have enabled the JMX on Weblogic AdminServer.
But I want to enable the JMX on the cluster servers such as ms1 listed below to monitor specific Java service. What shall I do? Thank you!
Servers:AdminServer(admin)
Clusters: ms1/ms2/ms3
[root#weblogic61 bin]# ps -ef |grep java
weblogic 3618 3571 0 Jun04 ? 03:14:41 /home/jdk/jdk1.7.0_45/bin/java -server -Xms1024m -Xmx2048m -XX:MaxPermSize=1024m -Dweblogic.Name=ms1 -Djava.security.policy=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Dweblogic.security.SSL.trustedCAKeyStore=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/cacerts -Djava.endorsed.dirs=/home/jdk/jdk1.7.0_45/jre/lib/endorsed:/home/weblogic/Oracle/Middleware/wlserver_12.1/endorsed -da -Dplatform.home=/home/weblogic/Oracle/Middleware/wlserver_12.1 -Dwls.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.management.discover=false -Dweblogic.management.server=http://192.168.97.61:7001 -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/home/weblogic/Oracle/Middleware/patch_wls1211/profiles/default/sysext_manifest_classpath:/home/weblogic/Oracle/Middleware/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
root 27588 27541 41 09:56 pts/0 00:00:25 /home/jdk/jdk1.7.0_45/bin/java -server -Xms1024m -Xmx2048m -XX:MaxPermSize=1024m -Dweblogic.Name=AdminServer -Djava.security.policy=/home/weblogic/Oracle/Middleware/wlserver_12.1/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Djava.endorsed.dirs=/home/jdk/jdk1.7.0_45/jre/lib/endorsed:/home/weblogic/Oracle/Middleware/wlserver_12.1/endorsed -Djava.rmi.server.hostname=192.168.97.61 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -da -Dplatform.home=/home/weblogic/Oracle/Middleware/wlserver_12.1 -Dwls.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.home=/home/weblogic/Oracle/Middleware/wlserver_12.1/server -Dweblogic.management.discover=true -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/home/weblogic/Oracle/Middleware/patch_wls1211/profiles/default/sysext_manifest_classpath:/home/weblogic/Oracle/Middleware/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
root 27638 27312 0 09:57 pts/1 00:00:00 grep java
zabbix 27853 1 0 Jun13 ? 00:14:16 java -server -classpath lib:lib/logback-classic-0.9.27.jar:lib/logback-core-0.9.27.jar:lib/org-json-2010-12-28.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-2.0.12.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java.pid -Dzabbix.listenIP=0.0.0.0 -Dzabbix.listenPort=10052 -Dzabbix.startPollers=5 com.zabbix.gateway.JavaGateway
The first question is where are those settings coming from for your admin server. My guess is you need to edit startWebLogic.sh and find where the following are being set:
JAVA_OPTIONS="-Dcom.sun.management.jmxremote.port=12345"
JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTIONS="${JAVA_OPTIONS} -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTIONS="${JAVA_OPTIONS} -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder"
export JAVA_OPTIONS
Thos settings are probably being explicitly set for your admin server only based on an if statement or some such.
You can also set those -D values for your managed server by going to:
Admin Console -> Servers -> MS -> Server Start -> JVM Arguments
Last, in the Weblogic Domain->Configuration->General->Advanced
Enable both - Platform MBean Server Enabled and Platform MBean Server Used
Admin Console -> Servers -> Server-1 -> Server Start -> JVM Arguments
-DUseSunHttpHandler=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.20.209
Admin Console -> Servers -> Server-2 -> Server Start -> JVM Arguments
-DUseSunHttpHandler=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8502 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.20.209
along with below command line parameters ,
-Dcom.sun.management.jmxremote.port='you jmx port'
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djavax.management.builder.initial=weblogic.management.jmx.mbeanserver.WLSMBeanServerBuilder
Sometimes in the linux servers , imx connection doesn't get succeeded. that is because , in cloud linux host, in /etc/hosts so that the hostname resolves to the host address.
the best way to fix it is, ping the particular linux server from other machine in network and use that host IP address in the
-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.
But never rely on the ipaddress that you get from linux server using ifconfig.me. the ip that you get there is masked one which is present in the host file.

Not able to connect to Remote JMX from visualVM

I am trying to connect to JMX running on Linux machine from the visualVM running on windows machine. I am using following settings for visualVM.
java -server -Dcom.sun.management.jmxremote -Djava.security.policy=~/jmx.all.policy -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=<mymachinesIP> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8766 myApp
myApp starts correctly
security policy file is as follows :
grant {
permission java.security.AllPermission;
};
netstat -an | grep 9000 // doesn't return anything i.e. port is not open
I tried everything on these forums but still not able to find any solution. Any help will be appreciated. Jstatd works fine though.

Java VisualVM not able to connect to Jboss

Java VisualVM not able to connect Jboss server, when jboss server running with option -b 0.0.0.0.
jboss run script - run.sh -c web -b 0.0.0.0
When i try to run jboss with this like - run.sh -c web -b {MyIp}
then Java VisualVM is able to connect jboss server.
Can any one help me how to connect while jboss running with first option ( -b 0.0.0.0)
I am using this configuration in run.conf file in jboss
JAVA_OPTS="$JAVA_OPTS -XX:PermSize=256m -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8077 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
Add this to JAVA_OPTS
JAVA_OPTS="$JAVA_OPTS -XX:PermSize=256m -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8077 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=0.0.0.0"
instead of 0.0.0.0 use your system IP.

Categories