2013-02-03 21:34:36 +01:00
|
|
|
#! /bin/sh
|
|
|
|
|
2016-07-18 17:30:39 +02:00
|
|
|
pluginfull="$0" # full name of plugin
|
|
|
|
plugin="${0##*/}" # name of plugin
|
2013-02-03 21:34:36 +01:00
|
|
|
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid"
|
|
|
|
cache="$MUNIN_PLUGSTATE/munin.$plugin.value"
|
|
|
|
|
2016-07-18 17:30:39 +02:00
|
|
|
IFACE="${0##*/if1sec_}" # interface
|
2013-02-03 21:34:36 +01:00
|
|
|
|
2013-02-04 10:18:40 +01:00
|
|
|
if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ]
|
|
|
|
then
|
|
|
|
echo "# Unknown Interface : $IFACE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-03 21:34:36 +01:00
|
|
|
if [ "$1" = "acquire" ]
|
|
|
|
then
|
2016-07-18 17:30:39 +02:00
|
|
|
(
|
|
|
|
exec <&- >&- 2>&-
|
|
|
|
while sleep 1
|
|
|
|
do
|
|
|
|
read tx < /sys/class/net/$IFACE/statistics/tx_bytes
|
|
|
|
read rx < /sys/class/net/$IFACE/statistics/rx_bytes
|
|
|
|
echo "$tx $rx"
|
|
|
|
done | awk "{
|
|
|
|
now = systime()
|
|
|
|
print \"${IFACE}_tx.value \" now \":\" \$1
|
|
|
|
print \"${IFACE}_rx.value \" now \":\" \$2
|
|
|
|
system(\"\")
|
|
|
|
}" >> $cache
|
|
|
|
) &
|
|
|
|
echo $! > $pidfile
|
|
|
|
exit 0
|
2013-02-03 21:34:36 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]
|
|
|
|
then
|
2016-07-18 17:30:39 +02:00
|
|
|
cat <<EOF
|
2013-02-03 21:34:36 +01:00
|
|
|
graph_title Interface 1sec stats for ${IFACE}
|
2016-07-18 17:30:39 +02:00
|
|
|
graph_category network
|
|
|
|
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 450d
|
|
|
|
graph_vlabel bits/sec
|
2013-02-03 21:34:36 +01:00
|
|
|
update_rate 1
|
2016-07-18 17:30:39 +02:00
|
|
|
${IFACE}_tx.label ${IFACE} TX bits
|
|
|
|
${IFACE}_tx.cdef ${IFACE}_tx,8,*
|
2013-02-04 10:18:40 +01:00
|
|
|
${IFACE}_tx.type DERIVE
|
|
|
|
${IFACE}_tx.min 0
|
2016-07-18 17:30:39 +02:00
|
|
|
${IFACE}_rx.label ${IFACE} RX bits
|
|
|
|
${IFACE}_rx.cdef ${IFACE}_rx,8,*
|
2013-02-04 10:18:40 +01:00
|
|
|
${IFACE}_rx.type DERIVE
|
|
|
|
${IFACE}_rx.min 0
|
2013-02-03 21:34:36 +01:00
|
|
|
EOF
|
2016-07-18 17:30:39 +02:00
|
|
|
# If max speed is easily available, report it. More complex
|
|
|
|
# code could be copied from "if_".
|
|
|
|
if [ -r /sys/class/net/$IFACE/speed ]
|
|
|
|
then
|
|
|
|
SPEED=$(cat /sys/class/net/$IFACE/speed)
|
|
|
|
echo "${IFACE}_rx.max" $((SPEED / 8 * 1000000))
|
|
|
|
echo "${IFACE}_tx.max" $((SPEED / 8 * 1000000))
|
|
|
|
echo "${IFACE}_rx.info Received traffic on the $IFACE interface. Maximum speed is ${SPEED} Mbps."
|
|
|
|
echo "${IFACE}_tx.info Transmitted traffic on the $IFACE interface. Maximum speed ${SPEED} Mbps."
|
|
|
|
fi
|
|
|
|
exit 0
|
2013-02-03 21:34:36 +01:00
|
|
|
fi
|
|
|
|
|
2016-07-18 17:30:39 +02:00
|
|
|
# Autorun logic
|
|
|
|
running=true
|
|
|
|
if [ ! -e ${cache} ]
|
|
|
|
then
|
|
|
|
# no cache file
|
|
|
|
running=false
|
|
|
|
elif [ ! -s ${cache} ]
|
|
|
|
then
|
|
|
|
# empty cache file
|
|
|
|
if [ -s ${pidfile} ]
|
|
|
|
then
|
|
|
|
# kill -0 will return success if this user is allowed to send
|
|
|
|
# a signal to the process. This means the PID exists and
|
|
|
|
# belongs to the plugin user, which should have few false
|
|
|
|
# positives.
|
|
|
|
if ! kill -0 $(cat ${pidfile})
|
|
|
|
then
|
|
|
|
running=false
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
running=false
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if ! $running
|
|
|
|
then
|
|
|
|
$0 acquire &
|
|
|
|
# wait a little so we have some data to report
|
|
|
|
sleep 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Finally: Print collected values, truncate to mark spot.
|
2013-02-04 10:18:40 +01:00
|
|
|
cat ${cache}
|
|
|
|
> ${cache}
|
2013-02-03 21:34:36 +01:00
|
|
|
|
|
|
|
exit 0
|