File: multips.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 (105 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!@@GOODSH@@
# -*- sh -*-

: <<=cut

=head1 NAME

multips - Munin plugin to monitor number of processes. Which processes
are configured in client-conf.d

=head1 APPLICABLE SYSTEMS

Any system with a pgrep, /usr/ucb/ps or other UCB compatible ps command.

=head1 CONFIGURATION

There is no default configuration.  This is an example:

  [multips]
     env.names pop3d imapd sslwrap
     env.regex_imapd ^[0-9]* imapd:
     env.regex_pop3d ^[0-9]* pop3d:

The regex parts are not needed if the name given in "names" can be
used to grep with directly.

=head1 INTERPRETATION

This plugin simply counts the total number of processes matching the
configured regular expressions.  The regular expressions are
interpreted by "grep" (and not grep -E or perl).

=head1 MAGIC MARKERS

  #%# family=manual
  #%# capabilities=autoconf


=head1 BUGS

None known

=head1 AUTHOR

Unknown

=head1 LICENSE

GPLv2

=cut

. "$MUNIN_LIBDIR/plugins/plugin.sh"


names=${names:-}


if [ "$1" = "autoconf" ]; then
	if [ -z "$names" ]; then
		echo "no (Configuration required)"
	else
		echo yes
	fi
	exit 0
fi

if [ -z "$names" ]; then
  echo "Configuration required"
  exit 1
fi

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

	echo graph_title Number of selected processes
	echo 'graph_category processes'
	echo 'graph_args --base 1000 --vertical-label processes -l 0'
	for name in $names; do
		fieldname=$(clean_fieldname "$name")
		eval REGEX='"${regex_'"$name"'-\<'"$name"'\>}"'

		echo "$fieldname.label $name"
		echo "$fieldname.draw LINE2"
		echo "$fieldname.info Processes matching this regular expression: /$REGEX/"
		print_warning "$fieldname"
		print_critical "$fieldname"
	done
	exit 0
fi

for name in $names; do
        fieldname=$(clean_fieldname "$name")
	printf "%s.value " "$fieldname"

	eval REGEX='"${regex_'"$name"'-\<'"$name"'\>}"'
	PGREP=$(command -v pgrep)
	if [ -n "$PGREP" ] && [ -x "$PGREP" ]; then
		"$PGREP" -f -l "$name" | grep "$REGEX" | 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
done