1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00
Munin-Contrib/plugins/systemd/systemd_units
Kael Shipman 161f2bb534
Added print_{warning,critical} for greater flexibility
Updated to allow admin to set custom values for warning and critical levels for all `$state` fields.
2018-10-17 17:10:21 -05:00

97 lines
1.8 KiB
Bash
Executable file

#!/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. You may optionally pass warning and critical values for any of the possible states (active,
reloading, inactive, failed, activating, deactivating) like so:
[systemd_units]
env.failed_warning 0
env.failed_critical 5
env.inactive_warning 10
env.inactive_critical 20
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
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 () {
cat << EOF
graph_title Systemd units state
graph_args -l 0
graph_category system
graph_scale no
graph_vlabel units
EOF
for state in $states; do
echo "$state.label $state"
echo "$state.draw AREASTACK"
# Set default alert levels for failed units
if [ "$state" = "failed" ]; then
failed_warning="${failed_warning:-0}" print_warning $state
failed_critical="${failed_critical:-10}" print_critical $state
else
print_warning $state
print_critical $state
fi
done
}
fetch () {
tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}')
for state in $states ; do
count=$(echo "$tmp" | grep -c "$state$")
echo "$state.value $count"
extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ')
if [ -n "$extinfo" ]; then
echo "$state.extinfo" "$extinfo"
fi
done
}
case $1 in
"autoconf")
autoconf
;;
"config")
config
;;
*)
fetch
;;
esac