Projet

Général

Profil

Révision dcfcbc2f

IDdcfcbc2faa8c6c99f90f8eebde06eb1bf23986b9
Parent c4d7d834
Enfant ec802cda

Ajouté par Kael Shipman il y a environ 7 ans

Added detailed filtering capabilities for systemd_units

Voir les différences:

plugins/systemd/systemd_units
13 13

  
14 14
=head1 CONFIGURATION
15 15

  
16
None needed. You may optionally pass warning and critical values for any of the possible states (active,
17
reloading, inactive, failed, activating, deactivating) like so:
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:
18 32

  
19 33
 [systemd_units]
20
     env.failed_warning 0
21
     env.failed_critical 5
22
     env.inactive_warning 10
23
     env.inactive_critical 20
24
     
25
Note that for failed units, default warning and critical values are set to 0 and 10, respectively. No other
26
states have default levels set.
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.
27 44

  
28 45
=head1 AUTHOR
29 46

  
30
Olivier Mehani <shtrom+munin@ssji.net>
47
Olivier Mehani <shtrom+munin@ssji.net> with contributions from Kael Shipman <kael.shipman@gmail.com>
31 48

  
32 49
=head1 LICENSE
33 50

  
......
51 68
	failed \
52 69
	activating \
53 70
	deactivating"
71

  
72
include="${include:-.*}"
73
exclude="${exclude:-^$}"
74

  
54 75
autoconf() {
55 76
	which systemctl >/dev/null && \
56 77
	       systemctl  --state=failed --no-pager --no-legend	>/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)"
......
73 94
}
74 95

  
75 96
fetch () {
76
	tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}')
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
77 102
	for state in $states ; do
78
		count=$(echo "$tmp" | grep -c "$state$")
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$")
79 118
		echo "$state.value $count"
80
		extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ')
119
		extinfo=$(echo "$state_tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ')
81 120
		if [ -n "$extinfo" ]; then
82 121
			echo "$state.extinfo" "$extinfo"
83 122
		fi

Formats disponibles : Unified diff