2018-07-04 04:14:33 +02:00
|
|
|
#!/bin/sh
|
2006-11-29 13:01:51 +01:00
|
|
|
#
|
|
|
|
# Plugin for monitor JVM activity - GC Count -
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# Symlink into /etc/munin/plugins/ and add the monitored
|
|
|
|
# alias name like :
|
|
|
|
#
|
|
|
|
# ln -s /usr/share/munin/plugins/jstat__gccount \
|
|
|
|
# /etc/munin/plugins/jstat_<jvm alias>_gccount
|
|
|
|
# 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:
|
|
|
|
#
|
2018-07-04 04:09:58 +02:00
|
|
|
# Target Java Virtual Machine to monitor are:
|
|
|
|
# Sun JDK 5.0 (http://java.sun.com/javase/)
|
|
|
|
# Sun JDK 8.0 (http://java.sun.com/javase/)
|
|
|
|
# BEA JRockit 5.0 (http://dev2dev.bea.com/jrockit/)
|
2006-11-29 13:01:51 +01:00
|
|
|
#
|
|
|
|
# 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:01:51 +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:01:51 +01:00
|
|
|
|
|
|
|
export JAVA_HOME
|
|
|
|
|
|
|
|
|
2018-07-04 04:09:58 +02:00
|
|
|
get_jdk_type() {
|
|
|
|
local version
|
|
|
|
if "${JAVA_HOME}/bin/java" -version 2>&1 | grep -qi 'jrockit'; then
|
|
|
|
echo "bea"
|
|
|
|
else
|
|
|
|
version=$("${JAVA_HOME}/bin/java" -version 2>&1 | grep '^java version' | awk '{print $3}' | sed -e 's/\"//g' | cut -d'_' -f 1)
|
|
|
|
if echo "$version" | grep -q '^1\.5\.'; then
|
|
|
|
echo "sun15"
|
|
|
|
else
|
|
|
|
echo "sun"
|
|
|
|
fi
|
2006-11-29 13:01:51 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-04 04:09:58 +02:00
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_config() {
|
2018-07-04 04:14:33 +02:00
|
|
|
echo "graph_title GC Count $graphtitle"
|
2018-07-04 03:53:19 +02:00
|
|
|
echo 'graph_args -l 0'
|
|
|
|
echo 'graph_vlabel GC Count(times)'
|
|
|
|
echo 'graph_total total'
|
|
|
|
echo 'graph_info GC Count'
|
|
|
|
echo 'graph_category virtualization'
|
|
|
|
|
|
|
|
echo 'Young_GC.label Young_GC'
|
|
|
|
echo 'Young_GC.min 0'
|
2018-07-04 04:14:33 +02:00
|
|
|
if [ "${JDK_TYPE}" = "bea" ]; then
|
2018-07-04 03:53:19 +02:00
|
|
|
echo 'Old_GC.label Old_GC'
|
|
|
|
echo 'Old_GC.min 0'
|
|
|
|
else
|
|
|
|
echo 'Full_GC.label Full_GC'
|
|
|
|
echo 'Full_GC.min 0'
|
|
|
|
fi
|
2006-11-29 13:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_stats() {
|
|
|
|
local pid_num="$1"
|
|
|
|
local awk_script
|
2018-07-04 04:14:33 +02:00
|
|
|
if [ "${JDK_TYPE}" = "bea" ]; then
|
2018-07-04 03:53:19 +02:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
awk_script='{ YC = $4; OC = $5; print "Young_GC.value " YGC; print "Old_GC.value " FGC; }'
|
2018-07-04 04:09:58 +02:00
|
|
|
elif [ "${JDK_TYPE}" = "sun15" ]; then
|
2018-07-04 03:53:19 +02:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
awk_script='{ YGC = $11; FGC = $13; print "Young_GC.value " YGC; print "Full_GC.value " FGC; }'
|
2018-07-04 04:09:58 +02:00
|
|
|
else
|
2018-07-04 20:29:52 +02:00
|
|
|
# example output of jstat for Java 1.8:
|
|
|
|
# S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
|
|
|
|
# 2048.0 2048.0 0.0 1344.0 694784.0 145013.5 1398272.0 414857.1 102400.0 96308.0 12544.0 11240.1 979 20.997 5 2.705 23.702
|
2018-07-04 04:09:58 +02:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
awk_script='{ YGC = $13; FGC = $15; print "Young_GC.value " YGC; print "Full_GC.value " FGC; }'
|
2018-07-04 03:53:19 +02:00
|
|
|
fi
|
|
|
|
"${JAVA_HOME}/bin/jstat" -gc "$pid_num" | tail -1 | awk "$awk_script"
|
2006-11-29 13:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# autoconf
|
|
|
|
#
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
|
|
|
|
if [ ! -x "${JAVA_HOME}/bin/jstat" ]; then
|
|
|
|
echo "no (No jstat found in ${JAVA_HOME}/bin)"
|
2018-09-16 05:03:47 +02:00
|
|
|
elif [ ! -f "$pidfilepath" ]; then
|
|
|
|
echo "no (missing file $pidfilepath)"
|
|
|
|
elif [ ! -r "$pidfilepath" ]; then
|
|
|
|
echo "no (cannot read $pidfilepath)"
|
|
|
|
else
|
|
|
|
echo "yes"
|
2006-11-29 13:01:51 +01:00
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2018-07-04 04:09:58 +02:00
|
|
|
JDK_TYPE=$(get_jdk_type)
|
|
|
|
|
|
|
|
|
2006-11-29 13:01:51 +01:00
|
|
|
if [ "$1" = "config" ]; then
|
2018-07-04 03:53:19 +02:00
|
|
|
print_config
|
|
|
|
exit 0
|
2006-11-29 13:01:51 +01:00
|
|
|
fi
|
|
|
|
|
2018-07-04 03:53:19 +02:00
|
|
|
print_stats "$(cat "$pidfilepath")"
|