Monitoring the JVM with SNMP + MRTG

By , 10 April 2009

Monitoring the JVM with SNMP + MRTG

Some time ago I blogged about monitoring the JVM with SNMP and OpenNMS. Here is an alternative method using the more lightweight MRTG which makes graphs such as the one below.

First you need to enable SNMP in your jvm by adding to your java command line. You can do this for tomcat by adding it to CATALINA_OPTS in your startup script. Next, you need to create that properties file properly. The following example configures the daemon to listen on all interfaces on port 1161. The ACL is disabled so you keep your security configuration in your firewall instead.

Monitoring the JVM with SNMP + MRTG

Now restart your JVM and test the SNMP daemon using snmpwalk:

$ snmpwalk -c public -v2c host:1161 .
SNMPv2-SMI::enterprises. = STRING: "pid@host"

Install MRTG with apt-get or whatever package manager your OS uses. Configuration isn't difficult, but there are a few caveats. First MRTG targets must explicity specify SNMP version 2 or you will get the following error:

SNMP Error:
Received SNMP response with error code
  error status: noSuchName
  index 3 (OID:
SNMPv1_Session (remote host: "xxx" [111.222.333.444].1161)

As explained in the MRTG Reference, the SNMP version to use is specified as a part of the target. Basically you're going to have something like ::::2 on the end of your targets.

The other one that got me is that the OIDs specified in the Java MIB need an extra .0 appended. You can download Java MIB if you want to use OID aliases. Just remember to add the .0 to the alias. To add the MIB to your MRTG configuration, add the path to the LoadMIBs option in the global section. Some useful OIDs to track are:


Variable OID

I chose to monitor the heap and threads using the following config:

# JVM Heap Usage
PageTop[heap]: <H1>JVM Heap Usage</H1>
Title[heap]: JVM Heap Usage
Target[heap]: / 1000000
MaxBytes[heap]: 1000
YLegend[heap]: Heap Used
ShortLegend[heap]: MB
LegendI[heap]: Used:
LegendO[heap]: Committed:
Options[heap]: nopercent,growright,gauge,noinfo

# JVM Threads
PageTop[threads]: <H1>JVM Threads</H1>
Title[threads]: JVM Threads
MaxBytes[threads]: 200
YLegend[threads]: JVM Threads
LegendI[threads]: Active:
LegendO[threads]: Max:
ShortLegend[threads]: threads
Options[threads]: nopercent,growright,gauge,noinfo

That's it, you can experiment further with the MRTG configuration as necessary. Have fun and try not to check your pretty new graphs too often. It's strangely addictive and can become pointless pretty quickly.

About Roger Keays

Monitoring the JVM with SNMP + MRTG

Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.

Leave a Comment

Please visit to add your comments.