Skip to content

Commit

Permalink
Add munin_status shell script to monitor log file
Browse files Browse the repository at this point in the history
Monitor log file on munin-master based on errors and more.
  • Loading branch information
drscream committed Sep 19, 2021
1 parent 918baea commit b985cd0
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions munin_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh
# -*- sh -*-
: <<=cut
=head1 NAME
munin_status - Plugin to monitor munin updates
=head1 APPLICABLE SYSTEMS
All systems with "sh", "pygtail", "awk" and "munin"
=head1 CONFIGURATION
The following is the default configuration
[munin_status]
user munin
env.muninupdate /var/log/munin/munin-update.log
env.pygtail /opt/local/bin/pygtail
You could trigger alerts on update failures
[munin_status]
env.munin_fatal_critical 0
env.munin_error_critical 0
env.munin_warning_warning 0
env.munin_warning_critical 5
=head1 INTERPRETATION
This plugin shows a graph with one line per munin state:
INFO, WARNING, ERROR, FATAL.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
0.1
=head1 AUTHOR
Thomas Merkel <tm@core.io>
=head1 LICENSE
GPLv2
=cut


##############################
# Includes

# shellcheck disable=SC1091
. "$MUNIN_LIBDIR/plugins/plugin.sh"

##############################
# Configurable variables
muninupdate=${muninupdate:-/var/log/munin/munin-update.log}
pygtail_bin=${pygtail_bin:-/opt/local/bin/pygtail}

##############################
# Functions

# Print the munin values
values() {
# Set offset
"$pygtail_bin" "$muninupdate" | awk '
BEGIN { split("INFO WARNING ERROR FATAL", a); for (i = 1; a[i]; ++i) A[i] = 0 }
{ for (i = 1; a[i]; ++i) if (match($0, a[i])) ++A[i] }
END { for (i = 1; a[i]; ++i) print "munin_"tolower(a[i])".value " A[i]}
'
chmod 640 "${muninupdate}.offset"
}

# Print the munin config
config() {
echo 'graph_title Munin update status groupped by log levels'
echo 'graph_info This graph shows INFO, WARNING, ERROR and FATAL status'
echo 'graph_category munin'
echo 'graph_vlabel Number of status'

echo 'graph_args --base 1000 -l 0'
echo 'graph_total total'
echo 'graph_printf %6.0lf'

echo 'munin_info.label INFO'
print_warning munin_info
print_critical munin_info
echo 'munin_warning.label WARNING'
print_warning munin_warning
print_critical munin_warning
echo 'munin_error.label ERROR'
print_warning munin_error
print_critical munin_error
echo 'munin_fatal.label FATAL'
print_warning munin_fatal
print_critical munin_fatal
}

# Print autoconfiguration hint
autoconf() {
if [ -r "${muninupdate}" ] && [ -x "$pygtail_bin" ]; then
echo "yes"
else
echo "missing (${muninupdate} or (${pygtail_bin})"
fi
exit
}

##############################
# Main

case "$1" in
config)
config
;;
autoconf)
autoconf
;;
*)
values
;;
esac

0 comments on commit b985cd0

Please sign in to comment.