root / plugins / systemd / systemd_units @ dcfcbc2f
Historique | Voir | Annoter | Télécharger (3,68 ko)
| 1 | 160bd2f0 | Olivier Mehani | #!/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 | dcfcbc2f | Kael Shipman | 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 | 161f2bb5 | Kael Shipman | |
| 33 | [systemd_units] |
||
| 34 | dcfcbc2f | Kael Shipman | 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 | 160bd2f0 | Olivier Mehani | |
| 45 | =head1 AUTHOR |
||
| 46 | |||
| 47 | dcfcbc2f | Kael Shipman | Olivier Mehani <shtrom+munin@ssji.net> with contributions from Kael Shipman <kael.shipman@gmail.com> |
| 48 | 160bd2f0 | Olivier Mehani | |
| 49 | =head1 LICENSE |
||
| 50 | |||
| 51 | GPLv2 |
||
| 52 | |||
| 53 | =head1 MAGIC MARKERS |
||
| 54 | |||
| 55 | #%# family=auto |
||
| 56 | ef80db4b | Olivier Mehani | #%# capabilities=autoconf |
| 57 | 160bd2f0 | Olivier Mehani | |
| 58 | =cut |
||
| 59 | |||
| 60 | e4e5d363 | Lars Kruse | . "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 61 | 161f2bb5 | Kael Shipman | |
| 62 | eda5c9b4 | Kael Shipman | failed_warning="${failed_warning:-0}"
|
| 63 | failed_critical="${failed_critical:-10}"
|
||
| 64 | |||
| 65 | 160bd2f0 | Olivier Mehani | states="active \ |
| 66 | reloading \ |
||
| 67 | inactive \ |
||
| 68 | failed \ |
||
| 69 | activating \ |
||
| 70 | deactivating" |
||
| 71 | dcfcbc2f | Kael Shipman | |
| 72 | include="${include:-.*}"
|
||
| 73 | exclude="${exclude:-^$}"
|
||
| 74 | |||
| 75 | 160bd2f0 | Olivier Mehani | 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 | ef80db4b | Olivier Mehani | cat << EOF |
| 82 | 160bd2f0 | Olivier Mehani | 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 | ef80db4b | Olivier Mehani | for state in $states; do |
| 89 | echo "$state.label $state" |
||
| 90 | echo "$state.draw AREASTACK" |
||
| 91 | eda5c9b4 | Kael Shipman | print_warning $state |
| 92 | print_critical $state |
||
| 93 | ef80db4b | Olivier Mehani | done |
| 94 | 160bd2f0 | Olivier Mehani | } |
| 95 | |||
| 96 | fetch () {
|
||
| 97 | dcfcbc2f | Kael Shipman | # 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 | a9476f50 | Tomaz Solc | for state in $states ; do |
| 103 | dcfcbc2f | Kael Shipman | # 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 | adc00722 | Tomaz Solc | echo "$state.value $count" |
| 119 | dcfcbc2f | Kael Shipman | extinfo=$(echo "$state_tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') |
| 120 | a9476f50 | Tomaz Solc | if [ -n "$extinfo" ]; then |
| 121 | 38835f7a | Tomaz Solc | echo "$state.extinfo" "$extinfo" |
| 122 | a9476f50 | Tomaz Solc | fi |
| 123 | done |
||
| 124 | 160bd2f0 | Olivier Mehani | } |
| 125 | |||
| 126 | case $1 in |
||
| 127 | "autoconf") |
||
| 128 | autoconf |
||
| 129 | ;; |
||
| 130 | "config") |
||
| 131 | b31b861f | Olivier Mehani | config |
| 132 | 160bd2f0 | Olivier Mehani | ;; |
| 133 | *) |
||
| 134 | b31b861f | Olivier Mehani | fetch |
| 135 | 160bd2f0 | Olivier Mehani | ;; |
| 136 | esac |
