2016-08-14 14:19:37 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
systemd - Plugin to monitor systemd units state
|
|
|
|
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
|
|
|
|
Linux systems with systemd installed.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
None needed.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2016-10-25 12:21:24 +02:00
|
|
|
Olivier Mehani <shtrom+munin@ssji.net>
|
2016-08-14 14:19:37 +02:00
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
GPLv2
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
2016-10-25 12:21:24 +02:00
|
|
|
#%# capabilities=autoconf
|
2016-08-14 14:19:37 +02:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
states="active \
|
|
|
|
reloading \
|
|
|
|
inactive \
|
|
|
|
failed \
|
|
|
|
activating \
|
|
|
|
deactivating"
|
|
|
|
autoconf() {
|
|
|
|
which systemctl >/dev/null && \
|
|
|
|
systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)"
|
|
|
|
}
|
|
|
|
|
|
|
|
config () {
|
2016-10-25 12:21:24 +02:00
|
|
|
cat << EOF
|
2016-08-14 14:19:37 +02:00
|
|
|
graph_title Systemd units state
|
|
|
|
graph_args -l 0
|
|
|
|
graph_category system
|
|
|
|
graph_scale no
|
|
|
|
graph_vlabel units
|
|
|
|
EOF
|
2016-10-25 12:21:24 +02:00
|
|
|
for state in $states; do
|
|
|
|
echo "$state.label $state"
|
|
|
|
echo "$state.draw AREASTACK"
|
2016-10-27 13:25:27 +02:00
|
|
|
if [ "$state" = "failed" ]; then
|
2016-10-25 12:21:24 +02:00
|
|
|
echo "$state.warning 0"
|
|
|
|
echo "$state.critical 10"
|
|
|
|
fi
|
|
|
|
done
|
2016-08-14 14:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fetch () {
|
2016-10-27 17:49:03 +02:00
|
|
|
tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}')
|
2016-10-27 17:51:33 +02:00
|
|
|
for state in $states ; do
|
2016-10-27 17:52:30 +02:00
|
|
|
count=$(echo "$tmp" | grep -c "$state$")
|
|
|
|
echo "$state.value $count"
|
2016-10-27 17:51:33 +02:00
|
|
|
extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1)
|
|
|
|
if [ -n "$extinfo" ]; then
|
|
|
|
echo "$state.extinfo" $extinfo
|
|
|
|
fi
|
|
|
|
done
|
2016-08-14 14:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
"autoconf")
|
|
|
|
autoconf
|
|
|
|
;;
|
|
|
|
"config")
|
2016-10-27 13:25:27 +02:00
|
|
|
config
|
2016-08-14 14:19:37 +02:00
|
|
|
;;
|
|
|
|
*)
|
2016-10-27 13:25:27 +02:00
|
|
|
fetch
|
2016-08-14 14:19:37 +02:00
|
|
|
;;
|
|
|
|
esac
|