| 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.names apache2 nagios3 |
|---|
| 21 | |
|---|
| 22 | The names are used to grep with directly, after cleaning. So, this plugin |
|---|
| 23 | only supports very basic pattern matching. To fix: see multips |
|---|
| 24 | |
|---|
| 25 | =head1 INTERPRETATION |
|---|
| 26 | |
|---|
| 27 | This plugin adds up the RSS of all processes matching the |
|---|
| 28 | regex given as the process name, as reported by ps. |
|---|
| 29 | |
|---|
| 30 | =head1 MAGIC MARKERS |
|---|
| 31 | |
|---|
| 32 | #%# family=manual |
|---|
| 33 | #%# capabilities=autoconf |
|---|
| 34 | |
|---|
| 35 | =head1 VERSION |
|---|
| 36 | |
|---|
| 37 | 0.1 first release, based on: |
|---|
| 38 | multimemory.in 1590 2008-04-17 18:21:31Z matthias |
|---|
| 39 | As distributed in Debian. |
|---|
| 40 | |
|---|
| 41 | =head1 BUGS |
|---|
| 42 | |
|---|
| 43 | None known |
|---|
| 44 | |
|---|
| 45 | =head1 AUTHOR |
|---|
| 46 | |
|---|
| 47 | Originally: matthias? |
|---|
| 48 | Modified by: dominic@dubdot.com |
|---|
| 49 | |
|---|
| 50 | =head1 LICENSE |
|---|
| 51 | |
|---|
| 52 | GPLv2 |
|---|
| 53 | |
|---|
| 54 | =cut |
|---|
| 55 | |
|---|
| 56 | #. $MUNIN_LIBDIR/plugins/plugin.sh |
|---|
| 57 | . /usr/local/share/munin/plugins/plugin.sh |
|---|
| 58 | |
|---|
| 59 | if [ "$1" = "autoconf" ]; then |
|---|
| 60 | echo yes |
|---|
| 61 | exit 0 |
|---|
| 62 | fi |
|---|
| 63 | |
|---|
| 64 | if [ -z "$names" ]; then |
|---|
| 65 | echo "Configuration required" |
|---|
| 66 | exit 1 |
|---|
| 67 | fi |
|---|
| 68 | |
|---|
| 69 | if [ "$1" = "config" ]; then |
|---|
| 70 | echo graph_title Total memory usage |
|---|
| 71 | echo 'graph_category processes' |
|---|
| 72 | echo 'graph_args --base 1024 --vertical-label memory -l 0' |
|---|
| 73 | for name in $names; do |
|---|
| 74 | fieldname=$(clean_fieldname $name) |
|---|
| 75 | eval REGEX='"${regex_'$name'-\<'$name'\>}"' |
|---|
| 76 | |
|---|
| 77 | echo "$fieldname.label $name" |
|---|
| 78 | echo "$fieldname.draw LINE2" |
|---|
| 79 | echo "$fieldname.info Processes matching this regular expression: /$REGEX/" |
|---|
| 80 | done |
|---|
| 81 | exit 0 |
|---|
| 82 | fi |
|---|
| 83 | |
|---|
| 84 | for name in $names; do |
|---|
| 85 | fieldname=$(clean_fieldname $name) |
|---|
| 86 | printf "$fieldname.value " |
|---|
| 87 | |
|---|
| 88 | #ps auxww | grep $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 }' |
|---|
| 89 | #ps auxwwc -o rss | grep $name | grep -v grep | rev | sed -e 's/[ ].*$/' | /usr/bin/awk '{ total = total + $1 } END { print total * 1024 }' |
|---|
| 90 | #ps auxww | grep $name | grep -v grep | sed -e 's/[ ]{1,}/ /g' | /usr/bin/cut -d ' ' -f 6 | /usr/bin/awk '{ total = total + $1 } END { print total * 1024 }' |
|---|
| 91 | ps auxwwc -o rss | grep $name | grep -v grep | rev | /usr/bin/cut -d ' ' -f 1 | /usr/bin/awk '{ total = total + $1 } END { print total * 1024 }' |
|---|
| 92 | done |
|---|