Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can jconsole data be retrieved from the command line?

I am currently using jconsole to monitor performance metrics of my Java application and would like to script this data acquisition.

Is there a way to retrieve these VM metrics (heap memory usage, thread count, CPU usage etc.) to STDOUT?
The data in top -p PID -b -n 1 doesn't quite cut it.

Thanks

like image 935
Jonathan Avatar asked Jul 28 '09 13:07

Jonathan


People also ask

How do I export data from JConsole?

In summary graph you can export sub areas by right clicking and selecting 'export' to csv.

How do I run JConsole in terminal?

The jconsole executable can be found in JDK_HOME/bin, where JDK_HOME is the directory in which the Java Development Kit (JDK) is installed. If this directory is in your system path, you can start JConsole by simply typing jconsole in a command (shell) prompt.

How does JConsole connect to remote process?

To connect JConsole to server process, in the Remote Process section, specify the URL service:jmx:rmi:///jndi/rmi://localhost:2047/fmq and credentials pertaining to the server. Default user name and password are admin and passwd respectively.


2 Answers

jconsole just provides a wrapper around the JMX MBeans that are in the platform MBeanServer.

You can write a program to connect to your VM using the Attach API which would then query the MBeans.

Or you can expose the platform MBeanServer over RMI and query the MBeans that way.

See the java.lang.management package for more info

like image 101
Kevin Avatar answered Sep 30 '22 07:09

Kevin


Maybe jvmtop is worth a look.
It's a command-line tool which provides a live-view for several metrics.

Example output of the VM overview mode:

 JvmTop 0.4.1  amd64  8 cpus, Linux 2.6.32-27, load avg 0.12  http://code.google.com/p/jvmtop    PID MAIN-CLASS      HPCUR HPMAX NHCUR NHMAX    CPU     GC    VM USERNAME   #T DL  3370 rapperSimpleApp  165m  455m  109m  176m  0.12%  0.00% S6U37 web        21 11272 ver.resin.Resin [ERROR: Could not attach to VM] 27338 WatchdogManager   11m   28m   23m  130m  0.00%  0.00% S6U37 web        31 19187 m.jvmtop.JvmTop   20m 3544m   13m  130m  0.93%  0.47% S6U37 web        20 16733 artup.Bootstrap  159m  455m  166m  304m  0.12%  0.00% S6U37 web        46 
like image 28
MRalwasser Avatar answered Sep 30 '22 07:09

MRalwasser