2006-11-29 13:03:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Plugin for monitor JVM activity - GC Time -
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# Symlink into /etc/munin/plugins/ and add the monitored
|
|
|
|
# alias name like :
|
|
|
|
#
|
|
|
|
# ln -s /usr/share/munin/plugins/jstat__gctime \
|
|
|
|
# /etc/munin/plugins/jstat_<jvm alias>_gctime
|
|
|
|
# This should, however, be given through autoconf and suggest.
|
|
|
|
#
|
|
|
|
# Requirements:
|
|
|
|
#
|
|
|
|
# You need to execute your Java program under jsvc provided by
|
|
|
|
# http://jakarta.apache.org/commons/daemon/
|
|
|
|
# which enables you to run your Java program with specified
|
|
|
|
# pid file with -pidfile option.
|
|
|
|
# A Brief setup documentation is also available at
|
|
|
|
# http://tomcat.apache.org/tomcat-5.5-doc/setup.html
|
|
|
|
#
|
|
|
|
# Target:
|
|
|
|
#
|
|
|
|
# Target Java Virtual Machine to monitor are:
|
|
|
|
# Sun JDK 5.0 (http://java.sun.com/javase/) (default)
|
|
|
|
# BEA JRockit 5.0 (http://dev2dev.bea.com/jrockit/)
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# config (required)
|
|
|
|
#
|
|
|
|
# Config variables:
|
|
|
|
#
|
|
|
|
# pidfilepath - Which file path use. Defaults to '/var/run/jsvc.pid'
|
2018-07-04 03:12:42 +02:00
|
|
|
# javahome - override automatic detection of JRE directory
|
2018-07-04 03:17:45 +02:00
|
|
|
# graphtitle - Title of the graph (defaults to PID file location)
|
2006-11-29 13:03:49 +01:00
|
|
|
#
|
|
|
|
|
2018-07-04 03:12:42 +02:00
|
|
|
default_java_home=/usr/lib/jvm/default-java
|
|
|
|
[ -e "$default_java_home" ] || default_java_home=/usr/local/java/jdk
|
|
|
|
|
2018-07-04 03:09:45 +02:00
|
|
|
pidfilepath=${pidfilepath:-/var/run/jsvc.pid}
|
|
|
|
graphtitle=${graphtitle:-$pidfilepath}
|
2018-07-04 03:12:42 +02:00
|
|
|
JAVA_HOME=${javahome:-$default_java_home}
|
2006-11-29 13:03:49 +01:00
|
|
|
|
|
|
|
export JAVA_HOME
|
|
|
|
|
|
|
|
#
|
|
|
|
# Functions
|
|
|
|
#
|
|
|
|
chk_jdk()
|
|
|
|
{
|
|
|
|
isJRockit=`${JAVA_HOME}/bin/java -version 2>&1 | egrep -i 'jrockit'`
|
|
|
|
if [ -n "${isJRockit}" ]; then
|
|
|
|
JDK_TYPE="bea"
|
|
|
|
else
|
|
|
|
JDK_TYPE="sun"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
chk_version()
|
|
|
|
{
|
|
|
|
Version=`${JAVA_HOME}/bin/java -version 2>&1 | egrep '^java version' | awk '{print $3}' | sed -e 's/\"//g' | cut -d'_' -f 1`
|
|
|
|
if [ "${Version}" != "1.5.0" ]; then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_config() {
|
|
|
|
echo 'graph_title GC Time' $graphtitle
|
|
|
|
echo 'graph_args -l 0'
|
|
|
|
echo 'graph_vlabel GC Time(sec)'
|
|
|
|
echo 'graph_total total'
|
|
|
|
echo 'graph_info GC Time'
|
|
|
|
echo 'graph_category virtualization'
|
|
|
|
|
|
|
|
echo 'Young_GC.label Young_GC'
|
|
|
|
echo 'Young_GC.min 0'
|
|
|
|
if [ "${JDK_TYPE}" == "bea" ]; then
|
|
|
|
echo 'Old_GC.label Old_GC'
|
|
|
|
echo 'Old_GC.min 0'
|
|
|
|
echo 'Young_Pause.label Young_GC Pause'
|
|
|
|
echo 'Young_Pause.min 0'
|
|
|
|
echo 'Old_Pause.label Old_GC Pause'
|
|
|
|
echo 'Old_Pause.min 0'
|
|
|
|
else
|
|
|
|
echo 'Full_GC.label Full_GC'
|
|
|
|
echo 'Full_GC.min 0'
|
|
|
|
fi
|
2006-11-29 13:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_stats() {
|
|
|
|
local pid_num="$1"
|
|
|
|
local awk_script
|
|
|
|
if [ "${JDK_TYPE}" == "bea" ]; then
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
awk_script='{
|
|
|
|
YCTime = $6;
|
|
|
|
OCTime = $7;
|
|
|
|
YCPauseTime = $9;
|
|
|
|
OCPauseTime = $10;
|
|
|
|
print "Young_GC.value " YCTime;
|
|
|
|
print "Old_GC.value " OCTime;
|
|
|
|
print "Young_Pause.value " YCPauseTime;
|
|
|
|
print "Old_Pause.value " OCPauseTime; }'
|
|
|
|
else
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
awk_script='{
|
|
|
|
YGCT = $12;
|
|
|
|
FGCT = $14;
|
|
|
|
print "Young_GC.value " YGCT;
|
|
|
|
print "Full_GC.value " FGCT; }'
|
|
|
|
fi
|
|
|
|
"${JAVA_HOME}/bin/jstat" -gc "$pid_num" | tail -1 | awk "$awk_script"
|
2006-11-29 13:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# common for all argument
|
|
|
|
#
|
|
|
|
chk_jdk
|
|
|
|
|
|
|
|
#
|
|
|
|
# autoconf
|
|
|
|
#
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
|
|
|
|
if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
|
|
|
|
echo "no (No jstat found in ${JAVA_HOME}/bin)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
chk_version
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "no (Java version is invalid)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "${pidfilepath}" -o ! -r "${pidfilepath}" ]; then
|
|
|
|
echo "no (No such file ${pidfilepath} or cannot read ${pidfilepath}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "yes"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2018-07-04 03:53:19 +02:00
|
|
|
print_config
|
2006-11-29 13:03:49 +01:00
|
|
|
fi
|
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_stats "$(cat "$pidfilepath")"
|