]> jfr.im git - munin-plugins.git/blame - processes
support for a 2nd unbound plugin
[munin-plugins.git] / processes
CommitLineData
3decc5d1
JR
1#!/bin/sh
2# -*- sh -*-
3
4set -e
5
6: << =cut
7
8=head1 NAME
9
10processes - Plugin to monitor processes and process states.
11
12=head1 ABOUT
13
14This plugin requires munin-server version 1.2.5 or 1.3.3 (or higher).
15
16This plugin is backwards compatible with the old processes-plugins found on
17SunOS, Linux and *BSD (i.e. the history is preserved).
18
19All fields have colours associated with them which reflect the type of process
20(sleeping/idle = blue, running = green, stopped/zombie/dead = red, etc.)
21
22=head1 CONFIGURATION
23
24No configuration for this plugin.
25
26=head1 AUTHOR
27
28Copyright (C) 2006 Lars Strand
29
30=head1 LICENSE
31
32GNU General Public License, version 2
33
34=begin comment
35
36This file is part of Munin.
37
38This program is free software; you can redistribute it and/or modify it under
39the terms of the GNU General Public License as published by the Free Software
40Foundation; version 2 dated June, 1991.
41
42This program is distributed in the hope that it will be useful, but WITHOUT ANY
43WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
44PARTICULAR PURPOSE. See the GNU General Public License for more details.
45
46You should have received a copy of the GNU General Public License along with
47this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
48Street, Fifth Floor, Boston, MA 02110-1301 USA.
49
50=end comment
51
52=head1 MAGIC MARKERS
53
54=begin comment
55
56These magic markers are used by munin-node-configure when installing
57munin-node.
58
59=end comment
60
61 #%# family=auto
62 #%# capabilities=autoconf
63
64=cut
65
66# Search for program in $PATH unless predefined.
67awk=${awk:-awk}
68ps=${ps:-ps}
69
70# Find operating system
71OPERSYS=${OPERSYS:-$(uname | cut -f 1 -d _)}
72[ -z "$OPERSYS" ] && echo >&2 "Failed to detect environment via uname" && exit 1
73
74if [ "$1" = "autoconf" ]; then
75 case "$OPERSYS" in
76 Linux|SunOS|FreeBSD|OpenBSD|NetBSD|Darwin|CYGWIN)
77 if ! "$ps" >/dev/null 2>/dev/null; then
78 echo "no (ps=$ps failed)"
79 elif ! echo | "$awk" '{ print "Hei" }' >/dev/null 2>/dev/null; then
80 echo "no (awk=$awk failed)"
81 else
82 echo yes
83 fi
84 exit 0
85 ;;
86 *)
87 echo "no (unknown OS)"
88 exit 0
89 ;;
90 esac
91fi
92
93. "$MUNIN_LIBDIR/plugins/plugin.sh"
94
95# Define colours
96RUNNABLE='22ff22' # Green
97SLEEPING='0022ff' # Blue
98STOPPED='cc0000' # Darker red
99DEBUGGED='ffff00' # Yellow
100ZOMBIE='990000' # Darkest red
101UNINTERRUPTIBLE='ffa500' # Orange
102IDLE='4169e1' # Royal blue
103PAGING='00aaaa' # Darker turquoise
104INTERRUPT='ff00ff' # Fuchsia
105LOCK='ff3333' # Lighter red
106RUNNING='00ff7f' # Spring green
107DEAD='ff0000' # Red
108SUSPENDED='ff1493' # Deep pink
109TOTAL='c0c0c0' # Silver
110
111# Taken from ps(1)
112# R - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX, HP-UX (runable)
113# S - Linux, SunOS, FreeBSD*, OpenBSD*, NetBSD*, OSX*, HP-UX (sleeping)
114# T - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX, HP-UX (stopped)
115# Z - Linux, SunOS, FreeBSD, OpenBSD, NetBSD, OSX, HP-UX (zombie/terminated)
116# D - Linux, FreeBSD, OpenBSD, NetBSD (uninterruptible)
117# I - FreeBSD, OpenBSD, NetBSD, OSX, HP-UX (idle/intermediate)
118# W - Linux*, FreeBSD*, HP-UX (paging/interrupt/waiting)
119# L - FreeBSD (lock)
120# O - SunOS (running)
121# X - Linux, HP-UX* (dead)
122# U - OSX, NetBSD* (uninterruptible/suspended)
123# 0 - HP-UX (nonexistent)
124# *) Differ meaning
125
126if [ "$1" = "config" ]; then
127 echo "graph_title Processes"
128 echo "graph_info This graph shows the number of processes"
129 echo "graph_category processes"
130 echo "graph_args --base 1000 -l 0"
131 echo "graph_vlabel Number of processes"
132
133 # OS specific flags
134 if [ "$OPERSYS" = "Linux" ]; then
135 echo "graph_order sleeping idle stopped debugged zombie dead paging uninterruptible runnable processes"
136 echo "dead.label dead"
137 echo "dead.draw STACK"
138 echo "dead.colour $DEAD"
139 echo "dead.info The number of dead processes."
140 print_warning dead
141 print_critical dead
142 echo "paging.label paging"
143 echo "paging.draw STACK"
144 echo "paging.colour $PAGING"
145 echo "paging.info The number of paging processes (<2.6 kernels only)."
146 print_warning paging
147 print_critical paging
148 echo "debugged.label debug"
149 echo "debugged.draw STACK"
150 echo "debugged.colour $DEBUGGED"
151 echo "debugged.info The number of processes stopped for debugging"
152 print_warning debugged
153 print_critical debugged
154
155 elif [ "$OPERSYS" = "SunOS" ]; then
156 echo "graph_order sleeping stopped zombie runnable running total"
157 echo "running.label running"
158 echo "running.draw STACK"
159 echo "running.colour $RUNNING"
160 echo "running.info The number of processes that are running on a processor."
161 print_warning running
162 print_critical running
163 # Be backwards compatible.
164 echo "total.label total"
165 echo "total.draw LINE1"
166 echo "total.colour $TOTAL"
167 echo "total.info The total number of processes."
168 print_warning total
169 print_critical total
170
171 elif [ "$OPERSYS" = "FreeBSD" ]; then
172 echo "graph_order sleeping idle stopped zombie lock uninterruptible interrupt runnable processes"
173 echo "lock.label lock"
174 echo "lock.draw STACK"
175 echo "lock.colour $LOCK"
176 echo "lock.info The number of processes that are waiting to acquire a lock."
177 print_warning lock
178 print_critical lock
179 echo "interrupt.label interrupt"
180 echo "interrupt.draw STACK"
181 echo "interrupt.colour $INTERRUPT"
182 echo "interrupt.info The number of idle interrupt threads."
183 print_warning interrupt
184 print_critical interrupt
185
186 elif [ "$OPERSYS" = "OpenBSD" ]; then
187 echo "graph_order sleeping idle stopped zombie uninterruptible runnable processes"
188
189 elif [ "$OPERSYS" = "NetBSD" ]; then
190 echo "graph_order sleeping idle stopped zombie uninterruptible suspended runnable processes"
191 echo "suspended.label suspended"
192 echo "suspended.draw STACK"
193 echo "suspended.colour $SUSPENDED"
194 echo "suspended.info The number of processes that are suspended."
195 print_warning suspended
196 print_critical suspended
197
198 elif [ "$OPERSYS" = "Darwin" ]; then
199 echo "graph_order sleeping idle stopped zombie uninterruptible running processes"
200 echo "uninterruptible.label uninterruptible"
201 echo "uninterruptible.draw STACK"
202 echo "uninterruptible.colour $UNINTERRUPTIBLE"
203 echo "uninterruptible.info The number of uninterruptible processes (usually IO)."
204 print_warning uninterruptible
205 print_critical uninterruptible
206 elif [ "$OPERSYS" = "HP-UX" ]; then
207 echo "graph_order sleeping intermediate stopped terminated waiting growing nonexistent runnable processes"
208 echo "waiting.label waiting"
209 echo "waiting.draw STACK"
210 echo "waiting.colour $INTERRUPT"
211 echo "waiting.info The number of waiting processes."
212 print_warning waiting
213 print_critical waiting
214 echo "terminated.label terminated"
215 echo "terminated.draw STACK"
216 echo "terminated.colour $ZOMBIE"
217 echo "terminated.info The number of processes that are terminated."
218 print_warning terminated
219 print_critical terminated
220 echo "growing.label growing"
221 echo "growing.draw STACK"
222 echo "growing.colour $RUNNING"
223 echo "growing.info The number of growing processes."
224 print_warning growing
225 print_critical growing
226 echo "intermediate.label intermediate"
227 echo "intermediate.draw STACK"
228 echo "intermediate.colour $IDLE"
229 echo "intermediate.info The number of intermediate processes."
230 print_warning intermediate
231 print_critical intermediate
232 echo "nonexistent.label nonexistent"
233 echo "nonexistent.draw STACK"
234 echo "nonexistent.colour $LOCK"
235 echo "nonexistent.info The number of nonexistent processes."
236 print_warning nonexistent
237 print_critical nonexistent
238 fi
239
240 # Common flags for some OS
241 if [ "$OPERSYS" = "FreeBSD" ] || [ "$OPERSYS" = "OpenBSD" ] ||
242 [ "$OPERSYS" = "NetBSD" ] || [ "$OPERSYS" = "Darwin" ]; then
243 echo "idle.label idle"
244 echo "idle.draw STACK"
245 echo "idle.colour $IDLE"
246 echo "idle.info The number of processes that are idle (sleeping for longer than about 20 seconds)."
247 print_warning idle
248 print_critical idle
249 echo "sleeping.label sleeping"
250 echo "sleeping.draw AREA"
251 echo "sleeping.colour $SLEEPING"
252 echo "sleeping.info The number of processes that are sleeping for less than about 20 seconds."
253 print_warning sleeping
254 print_critical sleeping
255 elif [ "$OPERSYS" = "Linux" ]; then
256 echo "idle.label idle"
257 echo "idle.draw STACK"
258 echo "idle.colour $IDLE"
259 echo "idle.info The number of idle kernel threads (>= 4.2 kernels only)."
260 print_warning idle
261 print_critical idle
262 echo "sleeping.label sleeping"
263 echo "sleeping.draw AREA"
264 echo "sleeping.colour $SLEEPING"
265 echo "sleeping.info The number of sleeping processes."
266 print_warning sleeping
267 print_critical sleeping
268 elif [ "$OPERSYS" = "SunOS" ] || [ "$OPERSYS" = "HP-UX" ]; then
269 echo "sleeping.label sleeping"
270 echo "sleeping.draw AREA"
271 echo "sleeping.colour $SLEEPING"
272 echo "sleeping.info The number of sleeping processes."
273 print_warning sleeping
274 print_critical sleeping
275 fi
276
277 if [ "$OPERSYS" = "Linux" ] || [ "$OPERSYS" = "FreeBSD" ] ||
278 [ "$OPERSYS" = "OpenBSD" ] || [ "$OPERSYS" = "NetBSD" ]; then
279 echo "uninterruptible.label uninterruptible"
280 echo "uninterruptible.draw STACK"
281 echo "uninterruptible.colour $UNINTERRUPTIBLE"
282 echo "uninterruptible.info The number of uninterruptible processes (usually IO)."
283 print_warning uninterruptible
284 print_critical uninterruptible
285 fi
286
287 # Common (non-cygwin) flags
288 if [ "$OPERSYS" != "CYGWIN" ]; then
289 echo "stopped.label stopped"
290 echo "stopped.draw STACK"
291 echo "stopped.colour $STOPPED"
292 echo "stopped.info The number of stopped or traced processes."
293 print_warning stopped
294 print_critical stopped
295
296 echo "runnable.label runnable"
297 echo "runnable.draw STACK"
298 echo "runnable.colour $RUNNABLE"
299 echo "runnable.info The number of runnable processes (on the run queue)."
300 print_warning runnable
301 print_critical runnable
302 fi
303
304 if [ "$OPERSYS" != "CYGWIN" ] && [ "$OPERSYS" != "HP-UX" ]; then
305 echo "zombie.label zombie"
306 echo "zombie.draw STACK"
307 echo "zombie.colour $ZOMBIE"
308 echo "zombie.info The number of defunct ('zombie') processes (process terminated and parent not waiting)."
309 print_warning zombie
310 print_critical zombie
311 fi
312
313 if [ "$OPERSYS" != "SunOS" ]; then
314 # Not using 'graph_total' due to backwards compability. SunOS uses 'total'.
315 #echo 'graph_total total'
316 echo "processes.label total"
317 echo "processes.draw LINE1"
318 echo "processes.colour $TOTAL"
319 echo "processes.info The total number of processes."
320 print_warning processes
321 print_critical processes
322 fi
323
324 exit 0
325fi
326
327if [ "$OPERSYS" = "Linux" ]; then
328 # shellcheck disable=SC2016
329 "$ps" --no-header -eo s | "$awk" '
330{ processes++; stat[$1]++ }
331END {
332print "processes.value " 0+processes;
333print "uninterruptible.value " 0+stat["D"];
334print "runnable.value " 0+stat["R"];
335print "sleeping.value " 0+stat["S"];
336print "idle.value " 0+stat["I"];
337print "debugged.value " 0+stat["t"];
338print "stopped.value " 0+stat["T"];
339print "paging.value " 0+stat["W"];
340print "dead.value " 0+stat["X"];
341print "zombie.value " 0+stat["Z"];
342}'
343
344elif [ "$OPERSYS" = "SunOS" ]; then
345 # shellcheck disable=SC2016
346 "$ps" -e -o s | "$awk" '
347{ total++; stat[$1]++ }
348END {
349print "total.value " 0+total;
350print "running.value " 0+stat["O"];
351print "sleeping.value " 0+stat["S"];
352print "runnable.value " 0+stat["R"];
353print "stopped.value " 0+stat["T"];
354print "zombie.value " 0+stat["Z"];
355}'
356elif [ "$OPERSYS" = "FreeBSD" ]; then
357 # shellcheck disable=SC2016
358 "$ps" -axo state= | sed -e 's/^\(.\).*/\1/' | "$awk" '
359{ processes++; stat[$1]++ }
360END {
361print "processes.value " 0+processes;
362print "uninterruptible.value " 0+stat["D"];
363print "idle.value " 0+stat["I"];
364print "lock.value " 0+stat["G"];
365print "runnable.value " 0+stat["R"];
366print "sleeping.value " 0+stat["S"];
367print "stopped.value " 0+stat["T"];
368print "interrupt.value " 0+stat["W"];
369print "zombie.value " 0+stat["Z"];
370}'
371elif [ "$OPERSYS" = "OpenBSD" ]; then
372 # First line is header. Remove it.
373 # shellcheck disable=SC2016
374 "$ps" -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | "$awk" '
375{ processes++; stat[$1]++ }
376END {
377print "processes.value " 0+processes;
378print "uninterruptible.value " 0+stat["D"];
379print "idle.value " 0+stat["I"];
380print "runnable.value " 0+stat["R"];
381print "sleeping.value " 0+stat["S"];
382print "stopped.value " 0+stat["T"];
383print "zombie.value " 0+stat["Z"];
384}'
385elif [ "$OPERSYS" = "NetBSD" ]; then
386 # First line is header. Remove it.
387 # shellcheck disable=SC2016
388 "$ps" -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | "$awk" '
389{ processes++; stat[$1]++ }
390END {
391print "processes.value " 0+processes;
392print "uninterruptible.value " 0+stat["D"];
393print "idle.value " 0+stat["I"];
394print "suspended.value " 0+stat["U"];
395print "runnable.value " 0+stat["R"];
396print "sleeping.value " 0+stat["S"];
397print "stopped.value " 0+stat["T"];
398print "zombie.value " 0+stat["Z"];
399}'
400
401elif [ "$OPERSYS" = "Darwin" ]; then
402 # First line is header. Remove it.
403 # shellcheck disable=SC2016
404 "$ps" -axo state= | sed '1d' | sed -e 's/^\(.\).*/\1/' | "$awk" '
405{ processes++; stat[$1]++ }
406END {
407print "processes.value " 0+processes;
408print "uninterruptible.value " 0+stat["U"];
409print "idle.value " 0+stat["I"];
410print "runnable.value " 0+stat["R"];
411print "sleeping.value " 0+stat["S"];
412print "stopped.value " 0+stat["T"];
413print "zombie.value " 0+stat["Z"];
414}'
415
416elif [ "$OPERSYS" = "CYGWIN" ]; then
417 # First line is header. Remove it. Also remove WINPID duplicates.
418 # shellcheck disable=SC2016
419 "$ps" -aW | sed '1d' | cut -c 30-36 | sort -u | "$awk" '
420{ processes++; }
421END {
422print "processes.value " 0+processes;
423}'
424
425elif [ "$OPERSYS" = "HP-UX" ]; then
426 # First line is header. Remove it.
427 # shellcheck disable=SC2016
428 "$ps" -el | sed '1d' | "$awk" '{print $2}' | "$awk" '
429{ processes++; stat[$1]++ }
430END {
431print "processes.value " 0+processes;
432print "nonexistent.value " 0+stat["0"];
433print "sleeping.value " 0+stat["S"];
434print "waiting.value " 0+stat["W"];
435print "runnable.value " 0+stat["R"];
436print "intermediate.value " 0+stat["I"];
437print "terminated.value " 0+stat["Z"];
438print "stopped.value " 0+stat["T"];
439print "growing.value " 0+stat["X"];
440}'
441
442fi