Graphing JVM utilization with orca

The Sun JDK has included an SNMP agent since version 5, and the agent has a number of objects in its MIB that provide runtime utilization data. The current set of objects include thread utilization counters, garbage collection events, time spent performing garbage collection, heap usage, class loader activity, compiler metrics, etc. Graphing these values can help with performance analysis, since you can view activity over time. This data is also useful for capacity planningl, since the graphs can be used to size hardware for an application, and for forecasting future hardware upgrades.

Numerous tools are available to graph utilization data, but my personal favorite is Orca. Orca can graph arbitrary data, and is a perfect fit for generating JVM performance graphs. Configuring Orca to generate JVM performance graphs is a snap. To begin, you will first need to enable the Java SNMP agent. To enable the agent, you can add the “-Dcom.sun.management.snmp.interface” (interface to bind to), “-Dcom.sun.management.snmp.port” (use a different SNMP port other that the default, port 161), “-Dcom.sun.management.snmp.acl” (use ACLs to limit who can read and write to the server) and ” -Dcom.sun.management.snmp.acl.file” (ACL file to use) options to the java command line:

$ java -Dcom.sun.management.snmp.interface=192.168.1.10 \
        -Dcom.sun.management.snmp.port=8161 \
        -Dcom.sun.management.snmp.acl=true \
        -Dcom.sun.management.snmp.acl.file=/usr/java/jre/lib/management/snmp.acl …

The $JAVA_HOME/jre/lib/management/ directory contains a sample SNMP ACL file (aptly named snmp.acl.template) that can be tailored to fit your site’s security policy (if you use the default locations, you do not need to specify the last two parameters). After the SNMP agent is enabled, you can run jvmstats.pl from cron to collect statistics at specific intervals. Each time Jvmstats.pl runs, it will write the current values of the Java agent’s performance counters (e.g., number of active threads, time spent performing garbage collection, etc.) to the file pased to the “-f” option, and will add a header to the file if it doesn’t exist.

The example below show how jvmstats.pl can be used to connect to server foo.prefetch.net on UDP port 8161, collect the current set of JVM statistics, and write these statistics to a file (the file name should match up with the regex used in the Orca find_files configuration stanza):

$ jvmstats.pl -s foo.prefetch.net -p 8161 -c public
        -f /home/matty/java/jvmstats/server1_myappjvm/javallator-2007-11-05

$ cat /home/matty/java/jvmstats/server1_myappjvm/javallator-2007-11-05

TIMESTAMP JVMUPTIME JITTIME THREADSTOTAL THREADSACTIVE CLASSLOADS CLASSUNLOADS \
NGGCEVENTS OLDGCEVENTS NGGCTIME OLDGCTIME OBJECTFINALIZATION HEAPCOMMITTED \
HEAPUSED NONHEAPCOMMITTED NONHEAPUSED
1194308951 218176652 735 308464 10 1348 0 380934 0 5309065 0 0 \
266797056 165481912 19136512 7156344

After a few samples are taken, the orca utility can be run with the javallator.cfg configuration file to graph the data collected above (if you haven’t used Orca before, you can peruse my monitoring LDAP article to see how to configure it). This will result in a set of graphs that look similar to the samples posted to my website. I really dig Java, and having historical performance graphs handy sure makes performance analysis a whole lot easier!

2 thoughts on “Graphing JVM utilization with orca”

  1. Matty, thanks *hugely* for this. I’ve long despaired of getting anything useful out of our Jrun/ColdFusion setup. Had no idea one could do what you’ve shown!

    Haven’t looked in detail at your solution – skimmed only so far :-) – but have you any vague ideas on perhaps getting this data into SE/procallator?

    I’d personally prefer to have orca display the jvm use graphs with the solaris/webserver ones all in a nice neat (long…) page. Just makes it easier to compare. YMMV.

    My woolly thinking is to get some sort of cron job to grab the stats and add (yet another) modification to orcallator.se to pull that file and send it straight back out as part of the base dump for collection/graphing.

    Thoughts? Criticisms?

    Cheers!
    – Steve

  2. That is so cool. I didn’t know that. I was going to pull GC logs and use HPJTune but mine is JDK 1.4. Do you know anything that can give me real-time graphs for 1.4 ?

Leave a Reply

Your email address will not be published. Required fields are marked *