Created
March 31, 2012 08:54
-
-
Save wataru420/2261009 to your computer and use it in GitHub Desktop.
Munin plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# -*- sh -*- | |
: << =cut | |
=head1 NAME | |
java_log_errorcount - Plugin to count errors in java log | |
=head1 CONFIGURATION | |
This plugin uses the following configuration variables | |
[java_log_errorcount] | |
env.logfile - log file path | |
env.dateformat - log's date foramt | |
=head2 DEFAULT CONFIGURATION | |
The default configuration is | |
[java_log_errorcount] | |
env.logfile /usr/local/tomcat/logs/catalina.out | |
env.dateformat "%Y-%m-%d %H:%M:" | |
=head1 AUTHOR | |
@wataru420 | |
=head1 LICENSE | |
Unknown license | |
=head1 MAGIC MARKERS | |
#%# family=auto | |
#%# capabilities=autoconf | |
=cut | |
LOGFILE=/usr/local/tomcat/logs/catalina.out | |
if [ "$logfile" ]; then LOGFILE=$logfile ; fi | |
DATEFORMAT="%Y-%m-%d %H:%M:" | |
if [ "$dateformat" ]; then DATEFORMAT=$dateformat ; fi | |
if [ "$1" = "autoconf" ]; then | |
if [ -e ${LOGFILE} ]; then | |
echo yes | |
exit 0 | |
else | |
echo no | |
exit 1 | |
fi | |
fi | |
if [ "$1" = "config" ]; then | |
echo "graph_title java error count ${LOGFILE}" | |
echo 'graph_args --base 1000 -l 0' | |
echo 'graph_vlabel count/5min' | |
echo 'graph_category java' | |
echo 'graph_info Java logs data.' | |
echo 'fatal.label fatal count' | |
echo 'fatal.draw LINE2' | |
echo "fatal.info fatal count" | |
echo 'error.label error count' | |
echo 'error.draw LINE2' | |
echo "error.info error count" | |
echo 'warn.label warn count' | |
echo 'warn.draw LINE2' | |
echo "warn.info warn count" | |
exit 0 | |
fi | |
grep_log() | |
{ | |
COUNT=0 | |
for i in `seq 1 5` | |
do | |
DATE=`date --date "$i minutes ago" +"${DATEFORMAT}"` | |
#echo ${DATE} | |
TMPCOUNT=`grep "${DATE}" ${LOGFILE} | grep $1 | wc -l` | |
let COUNT=${TMPCOUNT}+${COUNT} | |
done | |
return ${COUNT} | |
} | |
grep_log "FATAL" | |
echo "fatal.value " $? | |
grep_log "ERROR" | |
echo "error.value " $? | |
grep_log "WARN" | |
echo "warn.value " $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[java_log_errorcount] | |
env.logfile /usr/local/tomcat/logs/app.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment