root / plugins / systemd / systemd_units @ dcfcbc2f
Historique | Voir | Annoter | Télécharger (3,68 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
: << =cut |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
systemd - Plugin to monitor systemd units state |
| 9 |
|
| 10 |
=head1 APPLICABLE SYSTEMS |
| 11 |
|
| 12 |
Linux systems with systemd installed. |
| 13 |
|
| 14 |
=head1 CONFIGURATION |
| 15 |
|
| 16 |
No configuration is required for this plugin. You may optionally pass warning and critical values for any |
| 17 |
of the possible states (active, reloading, inactive, failed, activating, deactivating), and you may |
| 18 |
additionally pass both global and state-specific include/exclude filters to include only units you care |
| 19 |
about and/or exclude units you don't care about. |
| 20 |
|
| 21 |
(Note that for failed units, default warning and critical values are set to 0 and 10, respectively. No other |
| 22 |
states have default levels set.) |
| 23 |
|
| 24 |
Value calculations for each state are made using the following algorithm (all filters performed using \`egrep\`): |
| 25 |
|
| 26 |
1. Global include rules are applied on the output of \`systemctl list-units --all --no-legend\`; |
| 27 |
2. Global exclude rules are then applied to the result of that; |
| 28 |
3. Then, for each state, this global output is further filtered by include, then exclude rules for the state; |
| 29 |
4. Then the result is filtered for the given state and the remaining units counted and listed. |
| 30 |
|
| 31 |
An example configuration might be something like this: |
| 32 |
|
| 33 |
[systemd_units] |
| 34 |
env.failed_warning 0 |
| 35 |
env.failed_critical 5 |
| 36 |
env.inactive_warning 10 |
| 37 |
env.inactive_critical 20 |
| 38 |
env.exclude boring |
| 39 |
env.inactive_exclude sleepy |
| 40 |
|
| 41 |
In the example above, we've overridden the default warning and critical levels for failed units, added warning |
| 42 |
and critical levels for inactive units, then filtered out boring units from all results and filtered out sleepy |
| 43 |
units from results for the inactive state. |
| 44 |
|
| 45 |
=head1 AUTHOR |
| 46 |
|
| 47 |
Olivier Mehani <shtrom+munin@ssji.net> with contributions from Kael Shipman <kael.shipman@gmail.com> |
| 48 |
|
| 49 |
=head1 LICENSE |
| 50 |
|
| 51 |
GPLv2 |
| 52 |
|
| 53 |
=head1 MAGIC MARKERS |
| 54 |
|
| 55 |
#%# family=auto |
| 56 |
#%# capabilities=autoconf |
| 57 |
|
| 58 |
=cut |
| 59 |
|
| 60 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 61 |
|
| 62 |
failed_warning="${failed_warning:-0}"
|
| 63 |
failed_critical="${failed_critical:-10}"
|
| 64 |
|
| 65 |
states="active \ |
| 66 |
reloading \ |
| 67 |
inactive \ |
| 68 |
failed \ |
| 69 |
activating \ |
| 70 |
deactivating" |
| 71 |
|
| 72 |
include="${include:-.*}"
|
| 73 |
exclude="${exclude:-^$}"
|
| 74 |
|
| 75 |
autoconf() {
|
| 76 |
which systemctl >/dev/null && \ |
| 77 |
systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)" |
| 78 |
} |
| 79 |
|
| 80 |
config () {
|
| 81 |
cat << EOF |
| 82 |
graph_title Systemd units state |
| 83 |
graph_args -l 0 |
| 84 |
graph_category system |
| 85 |
graph_scale no |
| 86 |
graph_vlabel units |
| 87 |
EOF |
| 88 |
for state in $states; do |
| 89 |
echo "$state.label $state" |
| 90 |
echo "$state.draw AREASTACK" |
| 91 |
print_warning $state |
| 92 |
print_critical $state |
| 93 |
done |
| 94 |
} |
| 95 |
|
| 96 |
fetch () {
|
| 97 |
# Get all units, filtering by global include/exclude rules |
| 98 |
local state_include state_exclude state_tmp tmp |
| 99 |
tmp=$(systemctl --no-pager --no-legend --all | egrep "$include" | egrep -v "$exclude" | awk '{print $1, $3}')
|
| 100 |
|
| 101 |
# For each state, echo the number of units and some extra info, filtering for state-specific include/excludes |
| 102 |
for state in $states ; do |
| 103 |
# Get state-specific include/excludes, if present |
| 104 |
state_include="$(eval echo "\$${state}_include")"
|
| 105 |
state_exclude="$(eval echo "\$${state}_exclude")"
|
| 106 |
state_tmp="$tmp" |
| 107 |
|
| 108 |
# Filter |
| 109 |
if [ -n "$state_include" ]; then |
| 110 |
state_tmp="$(echo "$state_tmp" | egrep "$state_include")" |
| 111 |
fi |
| 112 |
if [ -n "$state_exclude" ]; then |
| 113 |
state_tmp="$(echo "$state_tmp" | egrep -v "$state_exclude")" |
| 114 |
fi |
| 115 |
|
| 116 |
# Count and output |
| 117 |
count=$(echo "$state_tmp" | grep -c "$state$") |
| 118 |
echo "$state.value $count" |
| 119 |
extinfo=$(echo "$state_tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') |
| 120 |
if [ -n "$extinfo" ]; then |
| 121 |
echo "$state.extinfo" "$extinfo" |
| 122 |
fi |
| 123 |
done |
| 124 |
} |
| 125 |
|
| 126 |
case $1 in |
| 127 |
"autoconf") |
| 128 |
autoconf |
| 129 |
;; |
| 130 |
"config") |
| 131 |
config |
| 132 |
;; |
| 133 |
*) |
| 134 |
fetch |
| 135 |
;; |
| 136 |
esac |
