2

From the Jstat Documentation , jstat can be connected to a local as well as remote JVM. The URI can be formed as

 [protocol:][//]lvmid[@hostname[:port]/servername]

I have a JVM running on one of the servers (CentOS) with JMX enabled -

xyz   23878     1  0 Jun01 ?        04:37:00 java -Xms1g -Xmx1g -XX:NewSize=512m -Xloggc:../9301/logs/gc.log -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../9301/logs/oom.log **-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=19301 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false** -jar ../0.1.14/xyz-0.1.14.jar -serviceName <name> -dataCenter <name> servicePort 9301

I am able to connect to the JVM, from my local machine, using JVisualVM which uses a 2 step process -

  1. Prompts to add the remote machine via jstatd connection on default port 1099 -> I am able to do so and server gets added proving RMI Registry is available
  2. After Adding the server, you can add a JMX connection to the JVM on the exposed port -> Success as JMX is exposed by my program on port 19301 and I am able to view the details

I am, however, not able to use jstat for the same purpose though.

Running jstat -gc process_id@servername gives me the below exception -

RMI Registry not available at <servername>:1099
Connection refused to host: <servername>; nested exception is: 
    java.net.ConnectException: Connection refused

Checked various sources over the net and they talk about having the jstatd running which I believe is running as VisualVM was able to add the machine.

Ques: How should I frame the [vmid] part in the jstat command to connect

trincot
  • 317,000
  • 35
  • 244
  • 286
Sandeep Dharembra
  • 192
  • 1
  • 2
  • 8

1 Answers1

4

You need to run jstatd on a remote host in order to use jstat.

Having RMI Registry running is not enough. The Registry is just for registering various RMI services. -Dcom.sun.management.jmxremote option starts jmxrmi service (which works for VisualVM), but jstat looks for JStatRemoteHost service.

Once you've started jstatd, use jstat -options process_id@servername command to monitor the remote VM.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • Thanks a lot @apangin I stared jstatd on the server and it worked. I was able to access the JVM remotely via jstat- root 23438 19717 0 00:11 pts/1 00:00:00 jstatd -J-Djava.security.policy=all.policy all.policy had the following content - grant codebase "file:/opt/jdk/lib/tools.jar" { permission java.security.AllPermission; }; The point is to ensure that the file: in the policy file should have the correct path. The jstatd documentation has ".." to provide a generic example which was not needed in my case – Sandeep Dharembra Jun 22 '17 at 07:31