2015-09-20 20:15:53 +02:00
|
|
|
#!/bin/zsh
|
2009-12-15 15:16:21 +01:00
|
|
|
#
|
|
|
|
# Created by Jan Rękorajski <baggins@pld-linux.org> based on vserver_cpu_ plugin.
|
|
|
|
#
|
2015-09-20 20:15:53 +02:00
|
|
|
# Obtained from https://github.com/munin-monitoring/contrib.git
|
|
|
|
#
|
|
|
|
# Changes by Andras Korn, 2015:
|
|
|
|
#
|
|
|
|
# * Convert to zsh
|
|
|
|
# * Fix to remove dots from vserver names (replace them with _)
|
|
|
|
# * Drop support for old (pre 2.6.19) kernels
|
|
|
|
# * Replace cat | grep | cut pipelines with a single sed
|
|
|
|
# * Add env.stripdomain (a domain name to strip from the
|
|
|
|
# end of vserver names when generating labels; be sure
|
|
|
|
# to include the leading dot)
|
|
|
|
#
|
2009-12-15 15:16:21 +01:00
|
|
|
# Graph Vserver cumulative cpu usage stats
|
|
|
|
#
|
|
|
|
# Configuration variables
|
|
|
|
# vservers - specify the vservers to include in the graph (default: all)
|
|
|
|
#
|
|
|
|
# NOTE: If no configuration variable is set, the default will be used
|
|
|
|
#
|
|
|
|
# see vserver_resources for example uses of configuration files
|
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
VSERVERS=(${=vservers})
|
|
|
|
STRIPDOMAIN="$stripdomain"
|
2009-12-15 15:16:21 +01:00
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
INFO=($(sed 's/.*:\t//' /proc/virtual/info 2>/dev/null || echo '<none>'))
|
2009-12-15 15:16:21 +01:00
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
NAMELOC="nsproxy"
|
2009-12-15 15:16:21 +01:00
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
if [[ -z "$VSERVERS" ]] ; then
|
|
|
|
cd /proc/virtual
|
|
|
|
XIDS=($(echo *(/)))
|
2009-12-15 15:16:21 +01:00
|
|
|
else
|
|
|
|
# it's really more performant to specify vservers by ids or by linking but not in the configuration-file by name
|
|
|
|
XIDS=""
|
2015-09-20 20:15:53 +02:00
|
|
|
for i in $VSERVERS[@] ; do
|
|
|
|
if [[ -d /proc/virtual/$i ]] ; then
|
|
|
|
XIDS=($XIDS[@] $i)
|
2009-12-15 15:16:21 +01:00
|
|
|
else
|
2015-09-20 20:15:53 +02:00
|
|
|
for j in /proc/virtual/*(/) -type d; do
|
|
|
|
if [[ "$i" = $(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' $j/$NAMELOC) ]]; then
|
|
|
|
XIDS=($XIDS[@] ${j:t})
|
2009-12-15 15:16:21 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
if [[ "$1" = "config" ]]; then
|
2017-02-23 19:53:57 +01:00
|
|
|
echo 'graph_category virtualization'
|
2009-12-15 15:16:21 +01:00
|
|
|
echo 'graph_args --base 1000'
|
|
|
|
echo 'graph_title Vserver cpu usage'
|
|
|
|
echo 'graph_vlabel jiffies used per ${graph_period}'
|
|
|
|
echo 'graph_info Shows jiffies used on each vserver.'
|
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
for i in $XIDS[@]; do
|
|
|
|
LABEL=$(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' /proc/virtual/$i/$NAMELOC)
|
|
|
|
LABEL=${LABEL%$STRIPDOMAIN}
|
|
|
|
NAME=${LABEL//./_}
|
|
|
|
NAME=${NAME//-/_}
|
2009-12-15 15:16:21 +01:00
|
|
|
echo "${NAME}_hold.label on hold for cpu on $LABEL"
|
|
|
|
echo "${NAME}_hold.info on hold for cpu on $LABEL."
|
|
|
|
echo "${NAME}_hold.type COUNTER"
|
|
|
|
echo "${NAME}_scpu.label system cpu usage for $LABEL"
|
|
|
|
echo "${NAME}_scpu.info system cpu usage for $LABEL."
|
|
|
|
echo "${NAME}_scpu.type COUNTER"
|
|
|
|
echo "${NAME}_ucpu.label user cpu usage for $LABEL"
|
|
|
|
echo "${NAME}_ucpu.info user cpu usage for $LABEL."
|
|
|
|
echo "${NAME}_ucpu.type COUNTER"
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-09-20 20:15:53 +02:00
|
|
|
for i in $XIDS[@]; do
|
|
|
|
LABEL=$(sed -n '/NodeName/s/^NodeName:[[:space:]]*//p' /proc/virtual/$i/$NAMELOC)
|
|
|
|
LABEL=${LABEL%$STRIPDOMAIN}
|
|
|
|
NAME=${LABEL//./_}
|
|
|
|
NAME=${NAME//-/_}
|
2009-12-15 15:16:21 +01:00
|
|
|
awk -v name=$NAME -v u=0 -v s=0 -v h=0 '
|
|
|
|
/^cpu [0-9]+:/ { u+=$3; s+=$4; h+=$5}
|
|
|
|
END {
|
|
|
|
print name "_hold.value " h
|
|
|
|
print name "_scpu.value " s
|
|
|
|
print name "_ucpu.value " u
|
|
|
|
}' /proc/virtual/$i/sched
|
|
|
|
done
|