2006-12-02 21:41:08 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Script to monitor CPU usage of Xen domains
|
|
|
|
#
|
|
|
|
# Author: unknown
|
2012-09-26 15:03:54 +02:00
|
|
|
# Modifications: Sebastian Wyder <sebastian.wyder@me.com>, Matthias Pfafferodt, syntron@web.de, Roland Mohrbacher
|
2006-12-02 21:41:08 +01:00
|
|
|
# License: GPL v. 2
|
|
|
|
#
|
|
|
|
# Parameters understood:
|
|
|
|
#
|
|
|
|
# conifg (required)
|
|
|
|
# autoconf (optional - used by munin-config)
|
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
# statefile: name of seen xen domains
|
2017-04-18 23:32:55 +02:00
|
|
|
statefile="$MUNIN_PLUGSTATE/munin-plugin-xen.state"
|
2006-12-02 21:41:08 +01:00
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
if which xm > /dev/null ; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "no (xm not found)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
|
|
|
|
if [ ! -e $statefile ]; then
|
|
|
|
touch $statefile
|
|
|
|
fi
|
|
|
|
|
2012-09-26 15:03:54 +02:00
|
|
|
echo 'graph_title Xen Domain Utilisation'
|
2006-12-02 21:41:08 +01:00
|
|
|
echo 'graph_args --base 1000 -l 0 --upper-limit 100 --rigid'
|
2011-06-24 09:57:18 +02:00
|
|
|
echo 'graph_scale no'
|
2006-12-02 21:41:08 +01:00
|
|
|
echo 'graph_vlabel %'
|
2014-09-06 22:28:53 +02:00
|
|
|
echo 'graph_category Virtualization'
|
2012-09-26 15:03:54 +02:00
|
|
|
echo 'graph_info This graph shows how many percent of the CPU time was used by each domain'
|
2006-12-02 21:41:08 +01:00
|
|
|
|
|
|
|
xm list | grep -v "^Name .* Time(s)$" | \
|
|
|
|
while read name domid mem cpu state time console; do
|
2011-06-24 09:57:18 +02:00
|
|
|
name=`echo $name | sed -e"s/[-.]/_/g"`
|
2006-12-02 21:41:08 +01:00
|
|
|
TEST=`less $statefile | grep "^${name}$" | wc -l`
|
|
|
|
if [ $TEST -ne 1 ]; then
|
|
|
|
echo "$name" >> $statefile
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
FIRST=1
|
|
|
|
cat $statefile | sort | \
|
|
|
|
while read name; do
|
|
|
|
echo "$name.label $name"
|
|
|
|
echo "$name.type COUNTER"
|
|
|
|
if [ $FIRST -eq 1 ]; then
|
|
|
|
echo "$name.draw AREA"
|
|
|
|
FIRST=0
|
|
|
|
else
|
|
|
|
echo "$name.draw STACK"
|
|
|
|
fi
|
|
|
|
echo "$name.min 0"
|
|
|
|
echo "$name.max 100"
|
2012-09-26 15:03:54 +02:00
|
|
|
echo "$name.info % of the CPU time spent for $name"
|
2006-12-02 21:41:08 +01:00
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
xm list | grep -v "^Name .* Time(s)$" | \
|
|
|
|
while read name domid mem cpu state time console; do
|
2011-06-24 09:57:18 +02:00
|
|
|
name=`echo $name | sed -e "s/[-.]/_/g"`
|
2006-12-02 21:41:08 +01:00
|
|
|
# only seconds
|
|
|
|
time=`echo $time | sed -e "s/\..//"`
|
|
|
|
# scale 60s/60s => 100%/60s
|
|
|
|
time=`echo "$time*100/60" | bc`
|
|
|
|
echo "$name.value $time"
|
|
|
|
done
|