SNMP Monitoring in Java VM

SNMP is not really simple, but quite useful, if you want to run standard monitoring tools like Nagios, Zero RRD or Cacti.

Even though Java offers JMX over RMI for runtime information like thread and memory consumption, you can also activate SNMP to read at least a subset.

In my opinion usage of a standard monitoring tool has several advantages over JMX-based visualization in JConsole or Lambda Probe:

  • Statistics fit into centralized reporting, e.g. for SLAs.
  • The tools are independent of the Java VM. If the VM freezes, the history is still available.

HowTo

First you need to enable the SNMP Agent in your Java VM. Please find the details here and an outline in the following list:

  • Prepare an ACL configuration at $JAVA_HOME/lib/management/snmp.acl. On Sun’s Java 6 for Ubuntu 10.04 64 Bit you will find these files in the package ia32-sun-java6-bin.
  • Use the following options on the command line while starting a JVM to enable SNMP: -Dcom.sun.management.snmp.port=7667 -Dcom.sun.management.snmp.acl.file=$JAVA_HOME/lib/management/snmp.acl

If you really put the snmp.acl at $JAVA_HOME/lib/management, it’s very likely, you will not need to specify the com.sun.management.snmp.acl.file option.

Now you are ready to read the internal state over SNMP:

  • Zero Agents module for Java SNMP just needs the port specified in conf/enabled/JavaSNMP.conf.
  • Please find some available OIDs in the source code of JavaSNMP.pm: DATA_OIDS
  • The full list of available values is included in the following MIB.