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 -Dcom.sun.management.config.file=snmp.properties 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.

com.sun.management.snmp.interface=0.0.0.0
com.sun.management.snmp.port=1161
com.sun.management.snmp.acl=false

Monitoring the JVM with SNMP + MRTG

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

$ snmpwalk -c public -v2c host:1161 .1.3.6.1.4.1.42.2.145.3.163.1.1.4.1
SNMPv2-SMI::enterprises.42.2.145.3.163.1.1.4.1.0 = 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: 1.3.6.1.2.1.1.3.0)
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
jvmMemoryHeapUsed 1.3.6.1.4.1.42.2.145.3.163.1.1.2.11.0
jvmMemoryHeapCommitted 1.3.6.1.4.1.42.2.145.3.163.1.1.2.12.0
jvmMemoryHeapMaxSize 1.3.6.1.4.1.42.2.145.3.163.1.1.2.13.0
jvmMemoryNonHeapUsed 1.3.6.1.4.1.42.2.145.3.163.1.1.2.21.0
jvmMemoryNonHeapCommited 1.3.6.1.4.1.42.2.145.3.163.1.1.2.22.0
jvmMemoryNonHeapMaxSize 1.3.6.1.4.1.42.2.145.3.163.1.1.2.23.0
jvmThreadCount 1.3.6.1.4.1.42.2.145.3.163.1.1.3.1.0
jvmThreadPeakCount 1.3.6.1.4.1.42.2.145.3.163.1.1.3.3.0

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]: 1.3.6.1.4.1.42.2.145.3.163.1.1.2.11.0&1.3.6.1.4.1.42.2.145.3.163.1.1.2.12.0:public@localhost:1161::::2 / 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
Target[threads]: 1.3.6.1.4.1.42.2.145.3.163.1.1.3.1.0&1.3.6.1.4.1.42.2.145.3.163.1.1.3.3.0:public@localhost:1161::::2
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. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food.

Leave a Comment

Please visit https://rogerkeays.com/blog/monitoring-the-jvm-with-snmp-mrtg to add your comments.

Comment posted by: Jim Anthony, last week
Hello, my name is James and I was just looking your website rogerkeays.com over and thought I would message you on your contact form and offer some help. I really like your site but I noticed you weren’t getting a lot of traffic and your Alexa ranking isn’t as strong as it could be. Fortunately, I may have an answer for you. I can get you 1,000’s of visitors looking at rogerkeays.com ready to buy your product, service or sign up for an offer and fast. Our advertising network of over 9000 websites provides a low cost and effective online marketing solutions that actually works. I can help your business get more online quality traffic by advertising your business on websites that are targeted to your specific market. The Internet is vast but you don’t have to spend huge amounts of cash to jump start your business. I can get you 10,000 highly targeted visitors directly to your website for as little as $39.00 for a 30 day trial run. https://worldtrafficsolutions.xyz It has taken us 12 years to perfect our system and in addition to being exciting, it works!! We also have a special offer of 200,000 Targeted visitors spread over 60 days for a special one time charge of $299.00. https://worldtrafficsolutions.xyz Also check out the short video here and see how everything works. Best Regards support@worldtrafficsolutions.xyz WorldTrafficSolutions.xyz https://worldtrafficsolutions.xyz To be placed on our removal list please visit: https://zfrmz.com/vTN2gJq4qHlWtaZ1YFQO
Comment posted by: Jim Anthony, 1 month ago
Hey, my name is James and I was just looking your website rogerkeays.com over and thought I would message you on your contact form and offer some help. I really like your site but I noticed you weren’t getting a lot of traffic and your Alexa ranking isn’t as strong as it could be. Fortunately, I may have an answer for you. I can get you 1,000’s of visitors looking at rogerkeays.com ready to buy your product, service or sign up for an offer and fast. Our advertising network of over 9000 websites provides a low cost and effective online marketing solutions that actually works. I can help your business get more online quality traffic by advertising your business on websites that are targeted to your specific market. The Internet is vast but you don’t have to spend huge amounts of cash to jump start your business. I can get you 10,000 highly targeted visitors directly to your website for as little as $39.00 for a 30 day trial run. https://worldtrafficsolutions.xyz It has taken us 12 years to perfect our system and in addition to being exciting, it works!! We also have a special offer of 200,000 Targeted visitors spread over 60 days for a special one time charge of $299.00. https://worldtrafficsolutions.xyz Also check out the short video here and see how everything works. Best Regards support@worldtrafficsolutions.xyz WorldTrafficSolutions.xyz https://worldtrafficsolutions.xyz To be placed on our removal list please visit: https://zfrmz.com/vTN2gJq4qHlWtaZ1YFQO