Projet

Général

Profil

Révision 29314a1f

ID29314a1f7abeb643dbe080337b42594ae399ec14
Parent d1497cb2
Enfant 354fbdf7

Ajouté par Micah Anderson and Andrei Morgan il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/vserver_loadavg
1
#!/bin/sh
2
#
3
# Copyright (C) 2007 Andrei Morgan
4
# Copyright (C) 2008 Micah Anderson
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; version 2 dated June,
9
# 1991.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19

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

  
27
# Example  /etc/munin/plugin-conf.d/munin-node 
28
#
29
# The following monitors the load average for vservers 1 and 3:
30
#
31
# [vserver_loadavg]
32
# user root
33
# env.vservers vserver1 vserver3
34

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

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

  
50
if [ "$1" = "autoconf" ]; then
51
        echo yes
52
        exit 0
53
fi
54

  
55

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

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

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

  
70
if [ -z "$VSERVERS" ] ; then
71
    XIDS=`find /proc/virtual/* -type d -exec basename {} \;`
72
else
73
    # it's really more performant to specify vservers by ids or not at all
74
    XIDS=""
75
    for i in $VSERVERS ; do
76
	if [ -d /proc/virtual/$i ] ; then
77
	    XIDS="${XIDS}${i} "
78
	else
79
	    for j in `find /proc/virtual/* -type d -exec basename {} \;` ; do
80
		if [ "$i" = "`cat /proc/virtual/$j/$NAMELOC |grep NodeName |cut -f2`" ] ; then
81
		    XIDS="${XIDS}${j} "
82
		fi
83
	    done
84
	fi
85
    done
86
fi
87
	
88
# If run with the "config"-parameter, give out information on how the
89
# graphs should look.  
90
if [ "$1" = "config" ]; then
91
        # The title of the graph
92
	echo 'graph_title loadavg of vserver'
93
        # Arguments to "rrdtool graph". In this case, tell it that the
94
        # lower limit of the graph is '0', and that 1k=1000 (not 1024)
95
	echo 'graph_args --base 1000 -l 0'
96
        # We want Cur/Min/Avg/Max unscaled (i.e. 0.42 load instead of
97
        # 420 milliload)
98
	echo 'graph_scale no'
99
        # The Y-axis label
100
	echo 'graph_vlabel loadavg'
101
	# graph information for the main table
102
	echo 'graph_info Shows 5-minute load average per vserver.'
103
        # Graph category. Defaults to 'other'
104
	echo 'graph_category vserver'
105
	for xid in $XIDS ; do
106
	# Specify the vservers
107
		LABEL=`cat /proc/virtual/$xid/$NAMELOC |grep NodeName |cut -f2`
108
		NAME=`echo $LABEL | cut -d. -f1 |  tr '-' '_'`
109
		echo "$NAME.label $LABEL: load average"
110
		echo "$NAME.info $NAME average load for the past 5 minutes"
111
	done 
112
        # Last, if run with the "config"-parameter, quit here (don't
113
        # display any data)
114
        exit 0
115
fi
116

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

  

Formats disponibles : Unified diff