Home » Clustering, Debian, Featured, Glassfish, How-to, Java

Snmp support for Glassfish 2.1.1 (with cluster support)

14 March 2011 One Comment

Why you choose SNMP when Glassfish have strong JMX support? I presume, the answer for all who use SNMP is (almost) the same: Because the architecture of current monitoring solution is not scalable enough, and I cannot load my monitoring servers with supplementary JAVA processes.

Before starting using SNMP I tried to see what solutions I have:
1. Re-design entire monitoring solution
2. Use SNMP

I’m a lazy person, so I choose to add SNMP support for all our clusters :).

To do that you should do 3 easy steps:

1. Upload the JVM-MANAGEMENT-MIB to your MIB folder on the monitoring server (In Debian is /usr/share/snmp/mibs/). This step is optional if you know all OIDS by yourself 🙂

2. Configure your glassfish
Log on your DAS, go to Configurations, choose your configuration, click on JVM Settings-> JVM Options and add the next 3 lines:

-Dcom.sun.management.snmp.port=162
-Dcom.sun.management.snmp.acl.file=/etc/java-6-sun/management/snmp.acl
-Dcom.sun.management.snmp.interface=${com.sun.aas.hostName}

(The same is for glassfish with cluster support)

3. Edit The ACL List
Edit /etc/java-6-sun/management/snmp.acl and add at the end of the file:


acl = {
{
communities = mypassword
access = read-only
managers = localhost, jack.randombugs.com
}
}

Where jack.randombugs.com is your monitoring server.

Now you should fix the permissions on /etc/java-6-sun/management/snmp.acl, because the glassfish will fail with the following error if this file doesn’t have the right permissions:

Error: Password file read access must be restricted: /etc/java-6-sun/management/snmp.acl

To fix that change the owner and permissions on snmp.acl file:


[randombugs@jack]# chown [your glassfish user (don't use root)] /etc/java-6-sun/management/snmp.acl
[randombugs@jack]# chmod o-r /etc/java-6-sun/management/snmp.acl
[randombugs@jack]# chmod g-r /etc/java-6-sun/management/snmp.acl

Now you are ready. Just restart your glassfish and test:


[randombugs@jack]$ snmpwalk -m all -v2c -c mypassword myserver:162 .1.3.6.1.4.1.42.2.145.3.163
JVM-MANAGEMENT-MIB::jvmClassesLoadedCount.0 = Gauge32: 596524
JVM-MANAGEMENT-MIB::jvmClassesTotalLoadedCount.0 = Counter64: 597036
JVM-MANAGEMENT-MIB::jvmClassesUnloadedCount.0 = Counter64: 512
JVM-MANAGEMENT-MIB::jvmClassesVerboseLevel.0 = INTEGER: silent(1)
JVM-MANAGEMENT-MIB::jvmMemoryPendingFinalCount.0 = Gauge32: 0
JVM-MANAGEMENT-MIB::jvmMemoryGCVerboseLevel.0 = INTEGER: silent(1)
JVM-MANAGEMENT-MIB::jvmMemoryGCCall.0 = INTEGER: supported(2)
JVM-MANAGEMENT-MIB::jvmMemoryHeapInitSize.0 = Counter64: 5368709120 bytes
JVM-MANAGEMENT-MIB::jvmMemoryHeapUsed.0 = Counter64: 1010489720 bytes
JVM-MANAGEMENT-MIB::jvmMemoryHeapCommitted.0 = Counter64: 5234491392 bytes
JVM-MANAGEMENT-MIB::jvmMemoryHeapMaxSize.0 = Counter64: 5234491392 bytes
JVM-MANAGEMENT-MIB::jvmMemoryNonHeapInitSize.0 = Counter64: 24313856 bytes
JVM-MANAGEMENT-MIB::jvmMemoryNonHeapUsed.0 = Counter64: 272285824 bytes
JVM-MANAGEMENT-MIB::jvmMemoryNonHeapCommitted.0 = Counter64: 289800192 bytes
JVM-MANAGEMENT-MIB::jvmMemoryNonHeapMaxSize.0 = Counter64: 318767104 bytes
JVM-MANAGEMENT-MIB::jvmMemManagerName.1 = STRING: CodeCacheManager
JVM-MANAGEMENT-MIB::jvmMemManagerName.2 = STRING: ParNew
JVM-MANAGEMENT-MIB::jvmMemManagerName.3 = STRING: ConcurrentMarkSweep
JVM-MANAGEMENT-MIB::jvmMemManagerState.1 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemManagerState.2 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemManagerState.3 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemGCCount.2 = Counter64: 39
JVM-MANAGEMENT-MIB::jvmMemGCCount.3 = Counter64: 70
JVM-MANAGEMENT-MIB::jvmMemGCTimeMs.2 = Counter64: 5941 milliseconds
JVM-MANAGEMENT-MIB::jvmMemGCTimeMs.3 = Counter64: 59 milliseconds
JVM-MANAGEMENT-MIB::jvmMemPoolName.1 = STRING: Code Cache
JVM-MANAGEMENT-MIB::jvmMemPoolName.2 = STRING: Par Eden Space
JVM-MANAGEMENT-MIB::jvmMemPoolName.3 = STRING: Par Survivor Space
JVM-MANAGEMENT-MIB::jvmMemPoolName.4 = STRING: CMS Old Gen
JVM-MANAGEMENT-MIB::jvmMemPoolName.5 = STRING: CMS Perm Gen
JVM-MANAGEMENT-MIB::jvmMemPoolType.1 = INTEGER: nonheap(1)
JVM-MANAGEMENT-MIB::jvmMemPoolType.2 = INTEGER: heap(2)
JVM-MANAGEMENT-MIB::jvmMemPoolType.3 = INTEGER: heap(2)
JVM-MANAGEMENT-MIB::jvmMemPoolType.4 = INTEGER: heap(2)
JVM-MANAGEMENT-MIB::jvmMemPoolType.5 = INTEGER: nonheap(1)
JVM-MANAGEMENT-MIB::jvmMemPoolState.1 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemPoolState.2 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemPoolState.3 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemPoolState.4 = INTEGER: valid(2)
JVM-MANAGEMENT-MIB::jvmMemPoolState.5 = INTEGER: valid(2)

Does anybody know about a C/C++ JMX client implementation ?

Update:

It seems, adding this new jvm options, will break the logging. The bug is documented here http://java.net/jira/browse/GLASSFISH-4013 and the bug is fixed only on Glassfish 3.

The exception generated is:

Could not load Logmanager "com.sun.enterprise.server.logging.ServerLogManager"
java.lang.ClassNotFoundException: com.sun.enterprise.server.logging.ServerLogManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.util.logging.LogManager$1.run(LogManager.java:166)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.(LogManager.java:156)
at java.util.logging.Logger.getLogger(Logger.java:287)
at sun.management.snmp.util.MibLogger.(MibLogger.java:57)
at sun.management.snmp.util.MibLogger.(MibLogger.java:42)
at sun.management.snmp.AdaptorBootstrap.(AdaptorBootstrap.java:46)
at sun.management.Agent.startAgent(Agent.java:113)
at sun.management.Agent.startAgent(Agent.java:239)

Good Luck!


One Comment »

  • Eva said:

    I really appreciate you sharing this. I did quite a bit of programming in college and i really loved it but unfortunately no java. I’m trying to study that on my own as it’s really useful to know these things in SEO.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.