aboutsummaryrefslogtreecommitdiff
path: root/files/munin/vserver_loadavg
blob: 43ce5e1ad549fafe5b5fd017ae4d19ac68c1134a (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
#!/bin/sh
#
# Copyright (C) 2007 Andrei Morgan
# Copyright (C) 2008 Micah Anderson
#
# 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.

# Graph Vserver load average
# 
# Configuration variables
#   vservers - specify the vservers to include in the graph (default: all)
#
# NOTE: If no configuration variables are set, the defaults will be used

# Example  /etc/munin/plugin-conf.d/munin-node 
#
# The following monitors the load average for vservers 1 and 3:
#
# [vserver_loadavg]
# user root
# env.vservers vserver1 vserver3

# Changelog
# version 0.1 - 2007 June 26
# Andrei Morgan <asm-debian@fifthhorseman.net>
#  - initial author, based upon vserver_resources by Holger Levsen and
#    Micah Anderson, and upon the examples in the munin wiki.
# version 0.2 - 2008 July 7
# Micah Anderson <micah@riseup.net>
#  - fix cvirt vs. nsproxy issue with newer kernels by adding $NAMELOC which
#    is aware of VCI_SPACES (> 2.6.19) as well as the older version

# If run with the "autoconf"-parameter, give our opinion on whether we
# should be run on this system or not. This is optional, and only used by
# munin-config. In the case of this plugin, we should most probably
# always be included whwn there is a vserver kernel.

if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi


# if vservers are specified, use them; the default is to use all.
VSERVERS="$vservers"

INFO=(`sed 's/.*:\t//' /proc/virtual/info 2>/dev/null || echo '<none>'`)
KCIN="$[ 16#${INFO[2]} ]";

# If this is 1, then VCI_SPACES is present in the kernel (new in 2.6.19)
if [ $[ (KCIN >> 10) & 1 ] -eq 1 ]
then 
    NAMELOC="nsproxy"
else 
    NAMELOC="cvirt"
fi

if [ -z "$VSERVERS" ] ; then
    XIDS=`find /proc/virtual/* -type d -exec basename {} \;`
else
    # it's really more performant to specify vservers by ids or not at all
    XIDS=""
    for i in $VSERVERS ; do
	if [ -d /proc/virtual/$i ] ; then
	    XIDS="${XIDS}${i} "
	else
	    for j in `find /proc/virtual/* -type d -exec basename {} \;` ; do
		if [ "$i" = "`cat /proc/virtual/$j/$NAMELOC |grep NodeName |cut -f2`" ] ; then
		    XIDS="${XIDS}${j} "
		fi
	    done
	fi
    done
fi
	
# If run with the "config"-parameter, give out information on how the
# graphs should look.  
if [ "$1" = "config" ]; then
        # The title of the graph
	echo 'graph_title loadavg of vserver'
        # Arguments to "rrdtool graph". In this case, tell it that the
        # lower limit of the graph is '0', and that 1k=1000 (not 1024)
	echo 'graph_args --base 1000 -l 0'
        # We want Cur/Min/Avg/Max unscaled (i.e. 0.42 load instead of
        # 420 milliload)
	echo 'graph_scale no'
        # The Y-axis label
	echo 'graph_vlabel loadavg'
	# graph information for the main table
	echo 'graph_info Shows 5-minute load average per vserver.'
        # Graph category. Defaults to 'other'
	echo 'graph_category vserver'
	for xid in $XIDS ; do
	# Specify the vservers
		LABEL=`cat /proc/virtual/$xid/$NAMELOC |grep NodeName |cut -f2`
		NAME=`echo $LABEL | cut -d. -f1 |  tr '-' '_'`
		echo "$NAME.label $LABEL: load average"
		echo "$NAME.info $NAME average load for the past 5 minutes"
	done 
        # Last, if run with the "config"-parameter, quit here (don't
        # display any data)
        exit 0
fi

for xid in $XIDS ; do
	LABEL=`cat /proc/virtual/$xid/$NAMELOC |grep NodeName |cut -f2`
	NAME=`echo $LABEL | cut -d. -f1 |  tr '-' '_'`
	echo -n "$NAME.value ";
	cat /proc/virtual/$xid/cvirt | grep loadavg: | cut -d' ' -f2	
done