root / plugins / systemd / systemd_units @ c6f88968
Historique | Voir | Annoter | Télécharger (4,22 ko)
| 1 | 1f184a35 | Valentin Lorentz | #!/bin/bash |
|---|---|---|---|
| 2 | 160bd2f0 | Olivier Mehani | # -*- 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 | 3699102c | Kael Shipman | Value calculations for each state are made using the following algorithm (all filters performed using |
| 25 | C<grep -E>): |
||
| 26 | dcfcbc2f | Kael Shipman | |
| 27 | 3699102c | Kael Shipman | 1. Global include rules are applied on the output of C<systemctl list-units --all --no-legend>; |
| 28 | dcfcbc2f | Kael Shipman | 2. Global exclude rules are then applied to the result of that; |
| 29 | 3. Then, for each state, this global output is further filtered by include, then exclude rules for the state; |
||
| 30 | 4. Then the result is filtered for the given state and the remaining units counted and listed. |
||
| 31 | |||
| 32 | An example configuration might be something like this: |
||
| 33 | 161f2bb5 | Kael Shipman | |
| 34 | 0d6b938c | pcy | =over 2 |
| 35 | |||
| 36 | 161f2bb5 | Kael Shipman | [systemd_units] |
| 37 | dcfcbc2f | Kael Shipman | env.failed_warning 0 |
| 38 | env.failed_critical 5 |
||
| 39 | env.inactive_warning 10 |
||
| 40 | env.inactive_critical 20 |
||
| 41 | env.exclude boring |
||
| 42 | env.inactive_exclude sleepy |
||
| 43 | 0d6b938c | pcy | env.silence_active_extinfo 1 |
| 44 | |||
| 45 | =back |
||
| 46 | dcfcbc2f | Kael Shipman | |
| 47 | In the example above, we've overridden the default warning and critical levels for failed units, added warning |
||
| 48 | and critical levels for inactive units, then filtered out boring units from all results and filtered out sleepy |
||
| 49 | 0d6b938c | pcy | units from results for the inactive state. In addition to that, only more extensive info of non-active units |
| 50 | are displayed in order to quickly see which units are failing and why in the webui. (By default, all extra info |
||
| 51 | about all units is displayed.) |
||
| 52 | 160bd2f0 | Olivier Mehani | |
| 53 | =head1 AUTHOR |
||
| 54 | |||
| 55 | ec802cda | Kael Shipman | Olivier Mehani <shtrom+munin@ssji.net> |
| 56 | Kael Shipman <kael.shipman@gmail.com> |
||
| 57 | 160bd2f0 | Olivier Mehani | |
| 58 | =head1 LICENSE |
||
| 59 | |||
| 60 | GPLv2 |
||
| 61 | |||
| 62 | =head1 MAGIC MARKERS |
||
| 63 | |||
| 64 | #%# family=auto |
||
| 65 | ef80db4b | Olivier Mehani | #%# capabilities=autoconf |
| 66 | 160bd2f0 | Olivier Mehani | |
| 67 | =cut |
||
| 68 | |||
| 69 | e4e5d363 | Lars Kruse | . "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 70 | 161f2bb5 | Kael Shipman | |
| 71 | eda5c9b4 | Kael Shipman | failed_warning="${failed_warning:-0}"
|
| 72 | failed_critical="${failed_critical:-10}"
|
||
| 73 | 0d6b938c | pcy | silence_active_extinfo="${silence_active_extinfo:-0}"
|
| 74 | eda5c9b4 | Kael Shipman | |
| 75 | 160bd2f0 | Olivier Mehani | states="active \ |
| 76 | reloading \ |
||
| 77 | inactive \ |
||
| 78 | failed \ |
||
| 79 | activating \ |
||
| 80 | deactivating" |
||
| 81 | dcfcbc2f | Kael Shipman | |
| 82 | include="${include:-.*}"
|
||
| 83 | exclude="${exclude:-^$}"
|
||
| 84 | |||
| 85 | 160bd2f0 | Olivier Mehani | autoconf() {
|
| 86 | which systemctl >/dev/null && \ |
||
| 87 | ec802cda | Kael Shipman | systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && \ |
| 88 | echo yes || \ |
||
| 89 | echo "no (No systemctl or error running it)" |
||
| 90 | 160bd2f0 | Olivier Mehani | } |
| 91 | |||
| 92 | config () {
|
||
| 93 | ef80db4b | Olivier Mehani | cat << EOF |
| 94 | 160bd2f0 | Olivier Mehani | graph_title Systemd units state |
| 95 | graph_args -l 0 |
||
| 96 | graph_category system |
||
| 97 | graph_scale no |
||
| 98 | graph_vlabel units |
||
| 99 | EOF |
||
| 100 | ef80db4b | Olivier Mehani | for state in $states; do |
| 101 | echo "$state.label $state" |
||
| 102 | echo "$state.draw AREASTACK" |
||
| 103 | eda5c9b4 | Kael Shipman | print_warning $state |
| 104 | print_critical $state |
||
| 105 | ef80db4b | Olivier Mehani | done |
| 106 | 160bd2f0 | Olivier Mehani | } |
| 107 | |||
| 108 | fetch () {
|
||
| 109 | ec802cda | Kael Shipman | # Get all units, filtering by global include/exclude rules |
| 110 | local state_include_var state_include state_exclude_var state_exclude global_unit_list state_unit_list |
||
| 111 | global_unit_list=$(systemctl --no-pager --no-legend --all | grep -E "$include" | grep -Ev "$exclude" | awk '{print $1, $3}')
|
||
| 112 | dcfcbc2f | Kael Shipman | |
| 113 | ec802cda | Kael Shipman | # For each state, echo the number of units and some extra info, filtering for state-specific include/excludes |
| 114 | a9476f50 | Tomaz Solc | for state in $states ; do |
| 115 | ec802cda | Kael Shipman | # Get state-specific include/excludes, if present |
| 116 | state_include_var="${state}_include"
|
||
| 117 | state_include="${!state_include_var}"
|
||
| 118 | state_exclude_var="${state}_exclude"
|
||
| 119 | state_exclude="${!state_exclude_var}"
|
||
| 120 | state_unit_list="$global_unit_list" |
||
| 121 | |||
| 122 | # Filter |
||
| 123 | if [ -n "$state_include" ]; then |
||
| 124 | state_unit_list="$(echo "$state_unit_list" | grep -E "$state_include")" |
||
| 125 | fi |
||
| 126 | if [ -n "$state_exclude" ]; then |
||
| 127 | state_unit_list="$(echo "$state_unit_list" | grep -Ev "$state_exclude")" |
||
| 128 | fi |
||
| 129 | |||
| 130 | # Count and output |
||
| 131 | count=$(echo "$state_unit_list" | grep -c "$state$") |
||
| 132 | adc00722 | Tomaz Solc | echo "$state.value $count" |
| 133 | ec802cda | Kael Shipman | extinfo=$(echo "$state_unit_list" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') |
| 134 | 0d6b938c | pcy | if [ "$silence_active_extinfo" = "0" ]; then |
| 135 | if [ -n "$extinfo" ]; then |
||
| 136 | echo "$state.extinfo" "$extinfo" |
||
| 137 | fi |
||
| 138 | else |
||
| 139 | if [ -n "$extinfo" ] && [ "$state" != "active" ]; then |
||
| 140 | echo "$state.extinfo" "$extinfo" |
||
| 141 | fi |
||
| 142 | a9476f50 | Tomaz Solc | fi |
| 143 | done |
||
| 144 | 160bd2f0 | Olivier Mehani | } |
| 145 | |||
| 146 | case $1 in |
||
| 147 | "autoconf") |
||
| 148 | autoconf |
||
| 149 | ;; |
||
| 150 | "config") |
||
| 151 | b31b861f | Olivier Mehani | config |
| 152 | 160bd2f0 | Olivier Mehani | ;; |
| 153 | *) |
||
| 154 | b31b861f | Olivier Mehani | fetch |
| 155 | 160bd2f0 | Olivier Mehani | ;; |
| 156 | esac |
