root / plugins / processes / multimemory @ 4b400a73
Historique | Voir | Annoter | Télécharger (2,31 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
: <<=cut |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
multimemory - Munin plugin to monitor memory usage of processes. Which processes |
| 9 |
are configured in client-conf.d |
| 10 |
|
| 11 |
=head1 APPLICABLE SYSTEMS |
| 12 |
|
| 13 |
Any system with a compatible ps command. |
| 14 |
|
| 15 |
=head1 CONFIGURATION |
| 16 |
|
| 17 |
There is no default configuration. This is an example: |
| 18 |
|
| 19 |
[multimemory] |
| 20 |
env.os freebsd |
| 21 |
env.names apache2 mysqld php-cgi |
| 22 |
|
| 23 |
Set env.os to freebsd if you are running this script on a machine which doesnt have |
| 24 |
GNU sed installed (FreeBSD / OpenBSD / Solaris ...), else set it to linux. |
| 25 |
|
| 26 |
The names are used to grep with directly, after cleaning. So, this plugin |
| 27 |
only supports very basic pattern matching. To fix: see multips |
| 28 |
|
| 29 |
=head1 INTERPRETATION |
| 30 |
|
| 31 |
This plugin adds up the RSS of all processes matching the |
| 32 |
regex given as the process name, as reported by ps. |
| 33 |
|
| 34 |
=head1 MAGIC MARKERS |
| 35 |
|
| 36 |
#%# family=manual |
| 37 |
#%# capabilities=autoconf |
| 38 |
|
| 39 |
=head1 VERSION |
| 40 |
0.3 light improvement in FreeBSD part of ps parsing |
| 41 |
0.2 second release, it should now work on machines without GNU sed |
| 42 |
0.1 first release, based on: |
| 43 |
multimemory.in 1590 2008-04-17 18:21:31Z matthias |
| 44 |
As distributed in Debian. |
| 45 |
|
| 46 |
=head1 BUGS |
| 47 |
|
| 48 |
None known |
| 49 |
|
| 50 |
=head1 AUTHOR |
| 51 |
|
| 52 |
Originally: matthias? |
| 53 |
Modified by: github.com/dominics github.com/yhager |
| 54 |
Thanks to: wix |
| 55 |
|
| 56 |
=head1 LICENSE |
| 57 |
|
| 58 |
GPLv2 |
| 59 |
|
| 60 |
=cut |
| 61 |
|
| 62 |
if [ -z "$MUNIN_LIBDIR" ]; then |
| 63 |
MUNIN_LIBDIR="`dirname $(dirname "$0")`" |
| 64 |
fi |
| 65 |
|
| 66 |
. $MUNIN_LIBDIR/plugins/plugin.sh |
| 67 |
|
| 68 |
if [ "$1" = "autoconf" ]; then |
| 69 |
echo yes |
| 70 |
exit 0 |
| 71 |
fi |
| 72 |
|
| 73 |
if [ -z "$names" -o -z "$os" ]; then |
| 74 |
echo "Configuration required" |
| 75 |
exit 1 |
| 76 |
fi |
| 77 |
|
| 78 |
if [ "$1" = "config" ]; then |
| 79 |
echo graph_title Total memory usage |
| 80 |
echo 'graph_category memory' |
| 81 |
echo 'graph_args --base 1024 --vertical-label memory -l 0' |
| 82 |
for name in $names; do |
| 83 |
fieldname=$(clean_fieldname $name) |
| 84 |
REGEX='\<'"$name"'\>' |
| 85 |
|
| 86 |
echo "$fieldname.label $name" |
| 87 |
echo "$fieldname.draw LINE2" |
| 88 |
echo "$fieldname.info Processes matching this regular expression: /$REGEX/" |
| 89 |
done |
| 90 |
exit 0 |
| 91 |
fi |
| 92 |
|
| 93 |
for name in $names; do |
| 94 |
fieldname=$(clean_fieldname $name) |
| 95 |
printf "$fieldname.value " |
| 96 |
|
| 97 |
if [ "$os" = "freebsd" ]; then |
| 98 |
ps awxo rss,command | grep -w $name | grep -v grep | /usr/bin/awk '{ total += $1 } END { print total * 1024 }'
|
| 99 |
else |
| 100 |
ps auxww | grep -w $name | grep -v grep | sed -re 's/[ ]{1,}/ /g' | /usr/bin/cut -d ' ' -f 6 | /usr/bin/awk '{ total = total + $1 } END { print total * 1024 }'
|
| 101 |
fi |
| 102 |
done |
