0

I'm trying to get JMX metrics from a currently running JVM. I'd like to be able to do this without having to enable it on the CLI when running the app. I'm trying to write a generic CLI utility, with some features missing from JConsole & JMC. Both JConsole and JMC do this. However there doesn't seem to be any documentation anywhere on how they are doing it.

2 Answers2

0

Depends. If you just want to get it from a locally running app, you can use the attach API. Here is an example on how to use the attach API to run diagnostic commands:

http://hirt.se/blog/?p=542

You can also use the attach API to get at the stub for local JMXRMI communication.

If you want to start up the remote agent, you can do that using the jcmd and the ManagementAgent.start diagnostic command.

Hirt
  • 1,664
  • 10
  • 12
  • I wrote a blog explaining in detail with working example: http://hirt.se/blog/?p=630 – Hirt Jan 29 '15 at 11:30
0

A little bit off-topic for cli app developer, but may be useful for command line users :

You can activate / deactivate "remote listening JMX agent" of a running JVM started without anything particular regarding JMX by using the jcmd command. Constraint: command must be run on the same host and with same user than the targeted jvm

enable JMX agent:

 jcmd <jvm_pid> ManagementAgent.start \
    jmxremote.port=<listen_on_tcp_port> \
    jmxremote.authenticate=false \
    jmxremote.ssl=false

disable JMX agent:

jcmd <jvm_pid> ManagementAgent.stop
Thomas LIMIN
  • 387
  • 4
  • 9