-
Notifications
You must be signed in to change notification settings - Fork 3
/
munin_status
executable file
·125 lines (112 loc) · 2.63 KB
/
munin_status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# -*- sh -*-
# =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
##############################
# 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