File: ps_.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (75 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!@@GOODSH@@
# -*- sh -*-

: << =cut

=head1 NAME

ps_ - Wildcard plugin to monitor number of processes

=head1 CONFIGURATION

This is a wildcard plugin.  The wildcard prefix link name should be the process
name to monitor.

This plugin uses the following configuration variables:

 [ps_*]
  env.regex - Regular expression used to filter output from pgrep / ps.

Whatever matches this regular expression is included in the count.

=head2 DEFAULT CONFIGURATION

The default configuration is to set "env.regex" to the link name prefix.

=head2 EXAMPLE WILDCARD USAGE

C<ln -s /usr/share/munin/node/plugins-auto/ps_ /etc/munin/node.d/ps_exim>

...will monitor number of exim-processes.

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=manual

=cut

. "$MUNIN_LIBDIR/plugins/plugin.sh"

myname=$(basename "$0" | sed 's/^ps_//g')

name="${name-\<$myname\>}"
REGEX="${regex-\<$name\>}"

if [ "$1" = "config" ]; then

	echo "graph_title Number of $myname processes"
	echo 'graph_args --base 1000 --vertical-label processes -l 0'
	echo 'graph_category processes'
	echo "count.label $myname"
	print_warning count
	print_critical count
	exit 0
fi

printf "count.value "

PGREP=/usr/bin/pgrep

if [ -x "$PGREP" ]; then
	$PGREP -f -l "$name" | grep "$REGEX" | grep -v grep | wc -l
elif [ -x /usr/ucb/ps ]; then
	# Solaris without pgrep. How old is that?
	/usr/ucb/ps auxwww | grep "$REGEX" | grep -v grep | wc -l
else
	ps auxwww | grep "$REGEX" | grep -v grep | wc -l
fi