LiveServer: multimemory.sh

File multimemory.sh, 2.2 KB (added by chris, 6 years ago)

Munin multimemory plugin

Line 
1#!/bin/sh
2# -*- sh -*-
3
4: <<=cut
5
6=head1 NAME
7
8multimemory - Munin plugin to monitor memory usage of processes. Which processes
9are configured in client-conf.d
10
11=head1 APPLICABLE SYSTEMS
12
13Any system with a compatible ps command.
14
15=head1 CONFIGURATION
16
17There is no default configuration.  This is an example:
18
19  [multimemory]
20     env.names apache2 nagios3
21
22The names are used to grep with directly, after cleaning. So, this plugin
23only supports very basic pattern matching. To fix: see multips
24
25=head1 INTERPRETATION
26
27This plugin adds up the RSS of all processes matching the
28regex 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
43None known
44
45=head1 AUTHOR
46
47Originally: matthias?
48Modified by: dominic@dubdot.com
49
50=head1 LICENSE
51
52GPLv2
53
54=cut
55
56#. $MUNIN_LIBDIR/plugins/plugin.sh
57. /usr/local/share/munin/plugins/plugin.sh
58
59if [ "$1" = "autoconf" ]; then
60        echo yes
61        exit 0
62fi
63
64if [ -z "$names" ]; then
65  echo "Configuration required"
66  exit 1
67fi
68
69if [ "$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
82fi
83
84for 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 }'
92done