Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_jstat

Rating
8 votes
Favoured:
2
Current Version
1.2
Last Release Date
2012-08-23
Compatible With
  • Nagios 3.x
Owner
License
LGPL
Hits
84571
Files:
FileDescription
check_jstat.shThe check command
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
A Nagios plugin to get memory statistics of a Java application using jstat

A Nagios plugin to get memory statistics of a Java application using jstat.

The process selection is done either by:

  • its pid (-p )
  • its service name (-s ) (assuming there is a /var/run/.pid file holding its pid)
  • its java name (-j ) where the java name depends ob how the java application has been launched (main class or jar/war in case of java -jar) (see jps).

It then call jstat -gc and jstat -gccapacity to catch current and maximum heap and perm sizes. What is called heap here is the edden + old generation space, while perm represents the permanent generation space.

If specified (with -w and -c options) values can be checked with WARNING or CRITICAL thresholds (apply to both heap and perm regions).

This plugin also attach perfomance data to the output:
pid=pid
heap=heap-size-used;heap-max-size;%ratio;warning-threshold-%ratio;critical-threshold-%ratio
perm=perm-size-used;perm-max-size;%ratio;warning-threshold-%ratio;critical-threshold-%ratio

Usage:

    chech_jstat.sh -v  
        Print version and exit"  
    chech_jstat.sh -h  
        Print this help nd exit  
    chech_jstat.sh -p  [-w <%ratio>] [-c <%ratio>]  
    chech_jstat.sh -s  [-w <%ratio>] [-c <%ratio>]  
    chech_jstat.sh -j  [-w <%ratio>] [-c <%ratio>]  
        -p        the PID of process to monitor  
        -s    the service name of process to monitor  
        -j  the java app (see jps) process to monitor  
                       if this name in blank (-j '') any java app is  
                       looked for (as long there is only one)  
        -w <%> the warning threshold ratio current/max in %  
        -c <%> the critical threshold ratio current/max in %  

This plugin may require to be run with sudo. In this case add a configuration in /etc/sudoers. For example if nagios is the user that run nagios (or NRPE deamon):

Defaults:nagios	!requiretty
nagios ALL=(root) NOPASSWD: /opt/nagios/libexec/check_jstat.sh

Reviews (5)
Hi,

This plugin was working nice for me. Yesterday I have upgraded JDK version to JDK 1.8 Update 31 and the plugin responds that 'can't find the process' (and the process exists).
It seems that the performance data is not in the expected 'Nagios plugins' format, which makes it hard(er) to graph these values.

The expected format is:

'label'=value[UOM];[warn];[crit];[min];[max]



https://nagios-plugins.org/doc/guidelines.html#AEN200

http://docs.icinga.org/latest/en/perfdata.html#formatperfdata
Nice plugin!

One thing though - for heap size capacity the script adds the values for EU and OU - but shouldn't it also add S0U?
Hi, i have probe this plugin, and it works only with root user, i have added the config in /etc/sudoers but mi execution with user nagios is the following:

-bash-4.1$ cd /srv/nagios/libexec/
-bash-4.1$ ./check_jstat.sh -s tomcat6
Could not attach to 11922
CRITICAL: Can't get GC statistics

I think that the problem is in jstat, which donĀ“t have permissions to see all java process (all users).

I add permisions to /etc/sudoers:

nagios ALL=(root) NOPASSWD: /usr/bin/jstat

And modify the plugin included "sudo" in calls to jstat lines:

gc=$(sudo jstat -gc $pid | tail -1 | sed -e 's/[ ][ ]*/ /g')

gccapacity=$(sudo jstat -gccapacity $pid | tail -1 | sed -e 's/[ ][ ]*/ /g')

And works perfectly!

If there is any alternative solution may be welcome :)

Good work!
byharakiri, August 13, 2012
1 of 2 people found this review helpful
The author copied code and forgot to adapt a variable.
Line 143 and 147: 'cs' should become 'ws' (otherwise no warning treshhold)
For all else this works fine. Jstat is also less intrusive to your JVM than jmap.
Be sure to add this plugin to /etc/sudoers or run the test as the same uid as the JVM. Otherwise jstat will get access denied.
Owner's reply

Thanks a lot for your review. I have fixed the copy/paste abuse in the version 1.1 and added a sample of sudoers configuration.