aboutsummaryrefslogtreecommitdiff
path: root/net/analyzer/munin/plugins/vserver_vmemory
blob: 008fb395310d6367f559bd13ff62f170e59edb76 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
#
# Copyright (C) 2006 Holger Levsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# Configuration variables
#   vservers - specify the vservers to include in the graph (default: all)
#   limits - if true, turn on limit graphing (default: false)
#
# NOTE: If no configuration variables are set, the defaults will be used

# Example /etc/munin/plugin-conf.d/munin-node 
#
# The first group monitors the vservers named "vserver1 vserver2
# vserver3 vserver4" and looks to see if the resource limit has been
# breached, if so it sends a message to nagios via send_nsca, and
# sends an email to notify that this has happened.
#
# The second monitors the vservers "vserver5 vserver6 vserver7" and 
# has no limit notifications turned on.
#
# The third monitors all vservers on the system, in one graph, and it has
# no limit notifications defined.
#
# You can use any combination of these to fit your needs.
#
#
# [vsrmem_group1]
# user root
# env.vservers vserver1 vserver2 vserver3 vserver4
# env.limits 1
# contacts nagios email
# contact.nagios.command /usr/bin/send_nsca -H your.nagios-host.here -c /etc/send_nsca.cfg
# contact.email.command mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email.address.here
#
# [vsrmem_group2]
# user root
# env.vservers vserver5 vserver6 vserver7
# env.limits 0
#
# [vserver_rmemory]
# user root
#
# Graph Vserver RSS usage and limits
#
# Changelog
# version 0.1 - 2006 April xx - Holger Levsen
#  - initial author
# version 0.2 - 2006 April 24 - Micah Anderson <micah@riseup.net>
#  - Add dynamic arch page size determination
#  - Some cleanup and clarification
# version 0.3 - 2006 May 3 - Micah Anderson <micah@riseup.net>
#  - Add ability to group vservers via environment vars
#  - Fix missing close quotes and standardize indents
#  - Add limit notification
#  - Update documentation to include info on groups and limits


VSERVERS="$vservers"
LIMITS="$limits"

if [ "$1" = "config" ]; then
    echo 'graph_title Virtual memory used by vservers'
    echo 'graph_title Vserver virtual memory'
    echo 'graph_args --base 1024k -l 0'
    echo 'graph_vlabel Size of VM pages'
    echo 'graph_category vserver'
    echo 'graph_info Shows virtual page size used by each vserver.'
        
    # do not assume we are on i386 where pagesize is 4096...
    pagesize=`perl -MPOSIX -e 'print POSIX::sysconf(_SC_PAGESIZE), "\n";'`

    if [ -z "$VSERVERS" ]; then	
        for i in `find /proc/virtual/* -type d -exec basename {} \;` ; do 
            NAME=`cat /proc/virtual/$i/cvirt |grep NodeName |cut -f2`
            echo "$NAME.label $NAME"
            echo "$NAME.info Size of virtual pages used by $NAME. (Number multipled by $pagesize to make human)"
            echo "$NAME.cdef $NAME,$pagesize,*"
            if [ ! -z "$LIMITS" -a "$LIMITS" = 1 ]; then
                cat /proc/virtual/$i/limit | awk -v name="$NAME" \
                    '{ if ( $1 == "VM:" ) 
                           {
                            if ( $2 >= $3 ) 
                                { 
                                    printf "%s.critical %d\n", name, $2 
                                }
                           }
                     }'
            fi
        done
    else
        for vserver in $vservers ; do
            echo "$vserver.label $vserver"
            echo "$vserver.info Size of virtual pages by $vserver. (Number multiplied by $pagesize to make human)"
            echo "$vserver.cdef $vserver,$pagesize,*"
            if [ ! -z "$LIMITS" -a "$LIMITS" = 1 ]; then
                XID=`/usr/sbin/vserver-info $vserver CONTEXT`
                LIMIT=`cat /proc/virtual/$XID/limit | grep RSS: | cut -f4`
                if [ ${LIMIT:-0} -gt 0 ]; then
                    echo "$NAME.critical $LIMIT"
                fi
            fi	    
        done
    fi
    exit 0
fi

if [ -z "$VSERVERS" ]; then
    for i in `find /proc/virtual/* -type d -exec basename {} \;` ; do
        NAME=`cat /proc/virtual/$i/cvirt | grep NodeName | cut -f2`
        cat /proc/virtual/$i/limit | awk -v name="$NAME" \
            '{ if ( $1 == "VM:" )
               printf "%s.value %d\n", name, $2 }'
    done
else
    for vserver in $VSERVERS ; do
        XID=`/usr/sbin/vserver-info $vserver CONTEXT`
        cat /proc/virtual/$XID/limit | awk -v name="$vserver" \
            '{ if ( $1 == "VM:" )
        printf "%s.value %d\n", name, $2 }'
    done
fi