Initial commit
This commit is contained in:
commit
a363bde348
15 changed files with 1189 additions and 0 deletions
files/usr/share/munin/plugins
40
files/usr/share/munin/plugins/udp-statistics
Normal file
40
files/usr/share/munin/plugins/udp-statistics
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
if ( $ARGV[0] ) {
|
||||
|
||||
if ( $ARGV[0] eq 'autoconf' ) {
|
||||
if ( -r '/bin/netstat') {
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
print "no\n";
|
||||
exit 0;
|
||||
|
||||
} elsif ( $ARGV[0] eq 'config' ) {
|
||||
print <<EOM;
|
||||
graph_title UDP Statistics
|
||||
graph_args --base 1000 -l 0
|
||||
graph_vlabel Packets/\${graph_period}
|
||||
graph_category network
|
||||
received.label Received
|
||||
received.draw AREA
|
||||
received.type DERIVE
|
||||
received.min 0
|
||||
errors.label Errors
|
||||
errors.draw LINE1
|
||||
errors.type DERIVE
|
||||
errors.min 0
|
||||
sent.label Sent
|
||||
sent.draw LINE1
|
||||
sent.type DERIVE
|
||||
sent.min 0
|
||||
EOM
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
@netstat = qx{/bin/netstat -us | awk '/packets sent/ \{ print "sent.value " \$1 \}
|
||||
/packets received/ \{ print "received.value " \$1 \}
|
||||
/packet receive errors/ \{ print "errors.value " \$1 \}'};
|
||||
|
||||
print @netstat;
|
132
files/usr/share/munin/plugins/vnstat_
Normal file
132
files/usr/share/munin/plugins/vnstat_
Normal file
|
@ -0,0 +1,132 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Munin plugin which reads the hourly, daily and monthly bandwidth usage.
|
||||
#
|
||||
# (c) 2011 Bram Schoenmakers <me@bramschoenmakers.nl>
|
||||
|
||||
#%# family=contrib
|
||||
#%# capabilities=autoconf
|
||||
|
||||
# par1 message
|
||||
error() {
|
||||
[ $# = 1 ] && echo "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# par1: "hourly", "daily" or "monthly"
|
||||
# par2: "tx" or "rx"
|
||||
getBandwidth() {
|
||||
[ $# != 2 ] && exit 1
|
||||
|
||||
local FIELD=-1
|
||||
[ $2 = "rx" ] && FIELD=4
|
||||
[ $2 = "tx" ] && FIELD=5
|
||||
|
||||
[ "$FIELD" -eq -1 ] && exit 1
|
||||
|
||||
local DATA=$(echo "$VNSTAT" | grep "^${1:0:1};0")
|
||||
local MIB=$(echo "$DATA" | cut -d ';' -f $FIELD)
|
||||
local KIB=$(echo "$DATA" | cut -d ';' -f $(( $FIELD + 2 )) )
|
||||
|
||||
echo "scale=3; $MIB + ( $KIB / 1024 )" | bc
|
||||
}
|
||||
|
||||
# par1: "hourly", "daily" or "monthly"
|
||||
# par2: value so far
|
||||
getEstimate() {
|
||||
[ $# != 2 ] && exit 1
|
||||
|
||||
case "$1" in
|
||||
"hourly")
|
||||
local MINUTESPASSED=$(( $( date +%M ) ))
|
||||
local MINUTESTOTAL=60
|
||||
;;
|
||||
"daily")
|
||||
local MINUTESPASSED=$( echo "$( date +%H ) * 60 + $( date +%M )" | bc )
|
||||
local MINUTESTOTAL=1440
|
||||
;;
|
||||
"monthly")
|
||||
local MINUTESPASSED=$( echo "( $( date +%d ) - 1 ) * 1440 + $( date +%H ) * 60 + $( date +%M )" | bc )
|
||||
local DAYSINMONTH=$(date -d "$(date +%Y)-$(($(date +%-m)+1))-01 -1 day" +%d)
|
||||
local MINUTESTOTAL=$(( $DAYSINMONTH * 1440 ))
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "scale=1; $MINUTESTOTAL * $2 / $MINUTESPASSED" | bc
|
||||
}
|
||||
|
||||
PARAMS=${0#*vnstat_}
|
||||
INTERFACE=$(echo "$PARAMS" | cut -d _ -f 1) # eth0
|
||||
PERIOD=$(echo "$PARAMS" | cut -d _ -f 2) # hourly, daily, monthly
|
||||
DIRECTION=$(echo "$PARAMS" | cut -d _ -f 3) # rx or tx
|
||||
|
||||
# determine whether estimates should be shown
|
||||
[ \( "${estimate:-0}" = 1 \) -o \( "${estimate:-0}" = "yes" \) -o \( "${estimate:-0}" = "true" \) ] && ESTIMATE=1 || ESTIMATE=0
|
||||
|
||||
# sanity checks
|
||||
[ "$PERIOD" = "hourly" ] || [ "$PERIOD" = "daily" ] || [ "$PERIOD" = "monthly" ] || error "Invalid period."
|
||||
[ "$DIRECTION" = "rx" ] || [ "$DIRECTION" = "tx" ] || [ "$DIRECTION" = "total" ] || [ "$DIRECTION" = "rxtx" ] || error "Invalid direction."
|
||||
|
||||
case "$1" in
|
||||
config)
|
||||
echo graph_category network
|
||||
echo graph_vlabel MiB
|
||||
|
||||
PERIODSTRING=${PERIOD%ly}
|
||||
PERIODSTRING=${PERIODSTRING/dai/day}
|
||||
if [ "$DIRECTION" = "rxtx" ]; then
|
||||
echo "graph_title Network bandwidth for $INTERFACE ($PERIOD, rx and tx)"
|
||||
echo value.label rx
|
||||
echo value2.label tx
|
||||
|
||||
# show estimates
|
||||
if [ $ESTIMATE -eq 1 ]; then
|
||||
echo "estimate.label rx estimate for this $PERIODSTRING"
|
||||
echo "estimate2.label tx estimate for this $PERIODSTRING"
|
||||
fi
|
||||
else
|
||||
echo "graph_title Network bandwidth for $INTERFACE ($PERIOD, $DIRECTION)"
|
||||
echo value.label $DIRECTION
|
||||
[ $ESTIMATE -eq 1 ] && echo "estimate.label estimate for this ${PERIODSTRING}"
|
||||
fi
|
||||
|
||||
exit 0;;
|
||||
autoconf)
|
||||
if ! which vnstat > /dev/null; then
|
||||
echo "no (vnstat unavailable)"
|
||||
elif ! which bc > /dev/null; then
|
||||
echo "no (bc unavailable)"
|
||||
else
|
||||
echo yes
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
VNSTAT=$(vnstat -i $INTERFACE --dumpdb)
|
||||
|
||||
if [ "$DIRECTION" = "total" ] || [ "$DIRECTION" = "rxtx" ]; then
|
||||
VALUE1=$(getBandwidth $PERIOD rx)
|
||||
[ $? = 1 ] && error "Could not obtain data."
|
||||
VALUE2=$(getBandwidth $PERIOD tx)
|
||||
[ $? = 1 ] && error "Could not obtain data."
|
||||
|
||||
[ "$DIRECTION" = "total" ] && VALUE1=$( echo "scale=3; $VALUE1 + $VALUE2" | bc )
|
||||
else
|
||||
VALUE1=$(getBandwidth $PERIOD $DIRECTION)
|
||||
[ $? = 1 ] && error "Could not obtain data."
|
||||
fi
|
||||
|
||||
if [ "$DIRECTION" = "rxtx" ]; then
|
||||
echo value.value $VALUE1
|
||||
echo value2.value $VALUE2
|
||||
|
||||
if [ "$ESTIMATE" -eq 1 ]; then
|
||||
echo estimate.value $(getEstimate $PERIOD $VALUE1)
|
||||
echo estimate2.value $(getEstimate $PERIOD $VALUE2)
|
||||
fi
|
||||
else
|
||||
echo value.value $VALUE1
|
||||
[ "$ESTIMATE" -eq 1 ] && echo estimate.value $(getEstimate $PERIOD $VALUE1)
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue