root / plugins / other / vserver_cpu_ @ 08b6b881
Historique | Voir | Annoter | Télécharger (6,03 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2006-2008 Holger Levsen and Micah Anderson |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of the GNU General Public License |
| 7 |
# as published by the Free Software Foundation; version 2 dated June, |
| 8 |
# 1991. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
|
| 19 |
# Graph Vserver cpu usage stats |
| 20 |
# |
| 21 |
# Configuration variables |
| 22 |
# vservers - specify the vservers to include in the graph (default: all) |
| 23 |
# |
| 24 |
# NOTE: If no configuration variable is set, the default will be used |
| 25 |
# |
| 26 |
# see vserver_resources for example uses of configuration files |
| 27 |
# |
| 28 |
# or links to define what to monitor: |
| 29 |
# vserver_cpu_ -> monitor cpu usage of all vservers on all cpus |
| 30 |
# vserver_hold_ -> monitor hold on all vservers on all cpus |
| 31 |
# vserver_hold_0 -> monitor hold on all vservers on cpu0 |
| 32 |
# vserver_hold_1 -> monitor hold on all vservers on cpu1 |
| 33 |
# vserver_hold_foo -> monitor hold on all cpus on vserver named foo |
| 34 |
# vserver_sys_foo -> monitor cpu usage on all cpus on vserver named foo |
| 35 |
|
| 36 |
# Changelog |
| 37 |
# version 0.2 - 2006 October 02 Holger Levsen <debian@layer-acht.org> |
| 38 |
# - label fixed: we measure jiffies not seconds |
| 39 |
# - Fix error that results if NodeName is set to include a domain name |
| 40 |
# - Fix hypens in NodeNames, replace them with underscores |
| 41 |
# - whitespace cleanup |
| 42 |
# version 0.3 - 2006 October 07 Holger Levsen <debian@layer-acht.org> |
| 43 |
# - rewrite of vserver_usercpu |
| 44 |
# - smp-aware |
| 45 |
# - can display hold too (third value in the cpu line(s) of /proc/virtual/<xid>/sched) |
| 46 |
# - no seperation between user and system cpu anymore |
| 47 |
# - handle identical vserver-names by using the vserver-id internally |
| 48 |
# version 0.4 - 2007, October 07 |
| 49 |
# Micah Anderson <micah@riseup.net> |
| 50 |
# - fixed variable name (thanks pietro) |
| 51 |
# version 0.5 - 2008, July 07 |
| 52 |
# Micah Anderson <micah@riseup.net> |
| 53 |
# - fixed number of CPU regexp to be more accurate |
| 54 |
# - added $NAMELOC - fixes plugin so it works with VCI_SPACES (> 2.6.19) as well as older version |
| 55 |
|
| 56 |
# TODO: |
| 57 |
# - comment the code or go mad |
| 58 |
# - add info how many jiffies per second are available on a machine |
| 59 |
# - user and system cpu are always added to each other, make it optional to split them? |
| 60 |
# - use /proc less often (100 times more overhead than talking to the kernel directly) |
| 61 |
# i.e. use something like pagesize=`perl -MPOSIX -e 'print POSIX::sysconf(_SC_PAGESIZE), "\n";'` |
| 62 |
|
| 63 |
|
| 64 |
VSERVERS="$vservers" |
| 65 |
|
| 66 |
INFO=(`sed 's/.*:\t//' /proc/virtual/info 2>/dev/null || echo '<none>'`) |
| 67 |
KCIN="$[ 16#${INFO[2]} ]";
|
| 68 |
|
| 69 |
# If this is 1, then VCI_SPACES is present in the kernel (new in 2.6.19) |
| 70 |
if [ $[ (KCIN >> 10) & 1 ] -eq 1 ] |
| 71 |
then |
| 72 |
NAMELOC="nsproxy" |
| 73 |
else |
| 74 |
NAMELOC="cvirt" |
| 75 |
fi |
| 76 |
|
| 77 |
if [ -z "$VSERVERS" ] ; then |
| 78 |
XIDS=`find /proc/virtual/* -type d -exec basename {} \;`
|
| 79 |
else |
| 80 |
# it's really more performant to specify vservers by ids or by linking but not in the configuration-file by name |
| 81 |
XIDS="" |
| 82 |
for i in $VSERVERS ; do |
| 83 |
if [ -d /proc/virtual/$i ] ; then |
| 84 |
XIDS="${XIDS}${i} "
|
| 85 |
else |
| 86 |
for j in `find /proc/virtual/* -type d -exec basename {} \;` ; do
|
| 87 |
if [ "$i" = "`cat /proc/virtual/$j/$NAMELOC |grep NodeName |cut -f2`" ] ; then |
| 88 |
XIDS="${XIDS}${j} "
|
| 89 |
fi |
| 90 |
done |
| 91 |
fi |
| 92 |
done |
| 93 |
fi |
| 94 |
|
| 95 |
BASEPARAM=`basename $0 | sed 's/^vserver_//'` |
| 96 |
MODE=`echo $BASEPARAM | sed 's/^hold.*//'` |
| 97 |
|
| 98 |
#debug=true |
| 99 |
|
| 100 |
if [ -z "$MODE" ] ; then |
| 101 |
MODE=hold |
| 102 |
TARGET=`echo $BASEPARAM | sed 's/^hold_//'` |
| 103 |
else |
| 104 |
MODE=cpu |
| 105 |
TARGET=`echo $BASEPARAM | sed 's/^cpu_//'` |
| 106 |
fi |
| 107 |
|
| 108 |
CPU1=0 |
| 109 |
if [ -n "$TARGET" ] ; then |
| 110 |
if [ "${#TARGET}" == 1 ] ; then
|
| 111 |
if [ $debug ] ; then echo $MODE, only on cpu $TARGET, for all vservers ; fi |
| 112 |
WHAT=ALLVSERVER |
| 113 |
CPU1=$TARGET |
| 114 |
else |
| 115 |
if [ $debug ] ; then echo $MODE on all cpus together, only for vserver $TARGET ; fi |
| 116 |
WHAT=VSERVER |
| 117 |
fi |
| 118 |
else |
| 119 |
if [ $debug ] ; then echo $MODE for all cpus, for all vservers ; fi |
| 120 |
WHAT=ALLVSERVER |
| 121 |
fi |
| 122 |
|
| 123 |
CPUS=$[ `grep ^processor /proc/cpuinfo|wc -l` -1 ] |
| 124 |
CPUS=`seq $CPU1 $CPUS` |
| 125 |
|
| 126 |
if [ $debug ] ; then |
| 127 |
echo cpus= $CPUS |
| 128 |
echo baseparam= $BASEPARAM |
| 129 |
echo mode= $MODE |
| 130 |
echo target= $TARGET |
| 131 |
echo what= $WHAT |
| 132 |
fi |
| 133 |
|
| 134 |
if [ "$1" = "config" ]; then |
| 135 |
echo 'graph_category vserver' |
| 136 |
echo 'graph_args --base 1000' |
| 137 |
if [ "$MODE" == "cpu" ] ; then |
| 138 |
echo 'graph_title Vserver cpu usage' |
| 139 |
echo 'graph_vlabel jiffies used per cpu per ${graph_period}'
|
| 140 |
echo 'graph_info Shows jiffies used per cpu on each vserver.' |
| 141 |
else |
| 142 |
echo 'graph_title Vserver cpu on hold' |
| 143 |
echo 'graph_vlabel jiffies on hold per cpu per ${graph_period}'
|
| 144 |
echo 'graph_info Shows jiffies on hold used per cpu on each vserver.' |
| 145 |
fi |
| 146 |
|
| 147 |
for j in $CPUS ; do |
| 148 |
A=0 |
| 149 |
for i in $XIDS ; do |
| 150 |
LABEL=`cat /proc/virtual/$i/$NAMELOC |grep NodeName |cut -f2` |
| 151 |
if [ "$WHAT" == "ALLVSERVER" ] || [ "$TARGET" == "$LABEL" ] ; then |
| 152 |
NAME=`echo $LABEL | cut -d. -f1 | tr '-' '_'` |
| 153 |
if [ "$MODE" == "cpu" ] ; then |
| 154 |
echo "${NAME}_$j.label cpu usage for cpu $j on $LABEL"
|
| 155 |
echo "${NAME}_$j.info cpu usage for cpu $j on $LABEL."
|
| 156 |
else |
| 157 |
echo "${NAME}_$j.label on hold for cpu $j on $LABEL"
|
| 158 |
echo "${NAME}_$j.info on hold for cpu $j on $LABEL."
|
| 159 |
fi |
| 160 |
echo "${NAME}_$j.type COUNTER"
|
| 161 |
if [ "$A" == 0 ] ; then |
| 162 |
echo "${NAME}_$j.draw AREA"
|
| 163 |
A=1 |
| 164 |
else |
| 165 |
echo "${NAME}_$j.draw STACK"
|
| 166 |
fi |
| 167 |
fi |
| 168 |
done |
| 169 |
done |
| 170 |
exit 0 |
| 171 |
fi |
| 172 |
|
| 173 |
for j in $CPUS ; do |
| 174 |
for i in $XIDS ; do |
| 175 |
LABEL=`cat /proc/virtual/$i/$NAMELOC |grep NodeName |cut -f2` |
| 176 |
if [ "$WHAT" == "ALLVSERVER" ] || [ "$TARGET" == "$LABEL" ] ; then |
| 177 |
NAME=`echo $LABEL | cut -d. -f1 | tr '-' '_'` |
| 178 |
echo -n "${NAME}_$j.value "
|
| 179 |
if [ "$MODE" == "cpu" ] ; then |
| 180 |
USERCPU=`cat /proc/virtual/$i/sched |grep "cpu $j"| cut -d' ' -f3` |
| 181 |
SYSCPU=`cat /proc/virtual/$i/sched |grep "cpu $j"| cut -d' ' -f4` |
| 182 |
echo $[$USERCPU + $SYSCPU] |
| 183 |
else |
| 184 |
cat /proc/virtual/$i/sched |grep "cpu $j"| cut -d' ' -f5 |
| 185 |
fi |
| 186 |
fi |
| 187 |
done |
| 188 |
done |
| 189 |
|
| 190 |
|
