summaryrefslogtreecommitdiff
path: root/files/plugins/xen_traffic_all
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2013-04-17 16:36:37 -0400
committerMicah Anderson <micah@riseup.net>2013-04-17 16:36:37 -0400
commit8f7c0071eb82591477876eeb3f309067853a3261 (patch)
treeb095f01b960b7ba3699da2dfa4d84cd5bb8a6361 /files/plugins/xen_traffic_all
parentea31faee76141646c173d88bd5bec5aa4a773c1c (diff)
parenta5ce0a9317fc5dd5228cff4c5b6d36366c17b6d5 (diff)
Merge branch 'master' into leap
Conflicts: README manifests/host/cgi.pp
Diffstat (limited to 'files/plugins/xen_traffic_all')
-rw-r--r--files/plugins/xen_traffic_all75
1 files changed, 42 insertions, 33 deletions
diff --git a/files/plugins/xen_traffic_all b/files/plugins/xen_traffic_all
index c5bbfbb..72f3b27 100644
--- a/files/plugins/xen_traffic_all
+++ b/files/plugins/xen_traffic_all
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Author: mario manno <projects@manno.name>
# Description: measure traffic for all xen hosts
#
@@ -14,7 +14,7 @@
# we cache xm list for 5 min for perfomance reasons
((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \
[ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \
- /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state
+ /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state
if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then
@@ -32,6 +32,19 @@ if [ "$1" = "autoconf" ]; then
exit 0
fi
+# we update network devices only twice an hour
+function net_state {
+ dom=$1
+ if [ `find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin +30 2> /dev/null | wc -l` -gt 0 ] || [ ! -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then
+ content=$(/usr/sbin/xm network-list $dom)
+ if [ $? -eq 0 ]; then
+ echo "${content}" | egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state
+ else
+ [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ] && rm /var/lib/munin/plugin-state/xm_net_$dom.state
+ fi
+ fi
+}
+
if [ "$1" = "config" ]; then
echo 'graph_title Xen Traffic'
echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
@@ -39,43 +52,38 @@ if [ "$1" = "config" ]; then
echo 'graph_category xen'
DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
- # we update network devices only twice an hour
- ((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \
- [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \
- (/usr/sbin/xm network-list $dom |\
- egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state)
- devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
- real_name=$( echo $dom | sed -e's/-/_/g' )
- name=$real_name
- for dev in $devs; do
- if [ ${#devs} -gt 1 ]; then
- name=$real_name"_"`echo $dev | sed 's/\./\_/'`
- fi
+ net_state $dom
+ if [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then
+ devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
+ real_name=$( echo $dom | sed -e's/-/_/g' )
+ name=$real_name
+ for dev in $devs; do
+ if [ ${#devs} -gt 1 ]; then
+ name=$real_name"_"`echo $dev | sed 's/\./\_/'`
+ fi
- echo $name'Down.label received'
- echo $name'Down.type COUNTER'
- echo $name'Down.graph no'
- echo "${name}Down.cdef ${name}Down,8,*"
- echo "${name}Up.label ${name}"
- echo $name'Up.type COUNTER'
- echo "${name}Up.negative ${name}Down"
- echo "${name}Up.cdef ${name}Up,8,*"
- done
+ echo $name'Down.label received'
+ echo $name'Down.type COUNTER'
+ echo $name'Down.graph no'
+ echo "${name}Down.cdef ${name}Down,8,*"
+ echo "${name}Up.label ${name}"
+ echo $name'Up.type COUNTER'
+ echo "${name}Up.negative ${name}Down"
+ echo "${name}Up.cdef ${name}Up,8,*"
+ done
+ fi
done
exit 0
fi
DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
- # we update network devices only twice an hour
- ((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \
- [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \
- (/usr/sbin/xm network-list $dom |\
- egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state)
- devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
- real_name=$( echo $dom | sed -e's/-/_/g' )
- name=$real_name
- for dev in $devs; do
+ net_state $dom
+ if [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then
+ devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state)
+ real_name=$( echo $dom | sed -e's/-/_/g' )
+ name=$real_name
+ for dev in $devs; do
if [ ${#devs} -gt 1 ]; then
name=$real_name"_"`echo $dev | sed 's/\./\_/'`
fi
@@ -86,6 +94,7 @@ for dom in $DOMAINS; do
print name"Down.value " $1 "\n"name"Up.value " $9 \
}' \
/proc/net/dev
- done
+ done
+ fi
done