root / plugins / network / if1sec_ @ c3660c2a
Historique | Voir | Annoter | Télécharger (2,24 ko)
| 1 |
#! /bin/sh |
|---|---|
| 2 |
|
| 3 |
pluginfull="$0" # full name of plugin |
| 4 |
plugin="${0##*/}" # name of plugin
|
| 5 |
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid" |
| 6 |
cache="$MUNIN_PLUGSTATE/munin.$plugin.value" |
| 7 |
|
| 8 |
IFACE="${0##*/if1sec_}" # interface
|
| 9 |
|
| 10 |
if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ] |
| 11 |
then |
| 12 |
echo "# Unknown Interface : $IFACE" |
| 13 |
exit 1 |
| 14 |
fi |
| 15 |
|
| 16 |
if [ "$1" = "acquire" ] |
| 17 |
then |
| 18 |
( |
| 19 |
exec <&- >&- 2>&- |
| 20 |
while sleep 1 |
| 21 |
do |
| 22 |
read tx < /sys/class/net/$IFACE/statistics/tx_bytes |
| 23 |
read rx < /sys/class/net/$IFACE/statistics/rx_bytes |
| 24 |
echo "$tx $rx" |
| 25 |
done | awk "{
|
| 26 |
now = systime() |
| 27 |
print \"${IFACE}_tx.value \" now \":\" \$1
|
| 28 |
print \"${IFACE}_rx.value \" now \":\" \$2
|
| 29 |
system(\"\") |
| 30 |
}" >> $cache |
| 31 |
) & |
| 32 |
echo $! > $pidfile |
| 33 |
exit 0 |
| 34 |
fi |
| 35 |
|
| 36 |
|
| 37 |
if [ "$1" = "config" ] |
| 38 |
then |
| 39 |
cat <<EOF |
| 40 |
graph_title Interface 1sec stats for ${IFACE}
|
| 41 |
graph_category network |
| 42 |
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 450d |
| 43 |
graph_vlabel bits/sec |
| 44 |
update_rate 1 |
| 45 |
${IFACE}_tx.label ${IFACE} TX bits
|
| 46 |
${IFACE}_tx.cdef ${IFACE}_tx,8,*
|
| 47 |
${IFACE}_tx.type DERIVE
|
| 48 |
${IFACE}_tx.min 0
|
| 49 |
${IFACE}_rx.label ${IFACE} RX bits
|
| 50 |
${IFACE}_rx.cdef ${IFACE}_rx,8,*
|
| 51 |
${IFACE}_rx.type DERIVE
|
| 52 |
${IFACE}_rx.min 0
|
| 53 |
EOF |
| 54 |
# If max speed is easily available, report it. More complex |
| 55 |
# code could be copied from "if_". |
| 56 |
if [ -r /sys/class/net/$IFACE/speed ] |
| 57 |
then |
| 58 |
SPEED=$(cat /sys/class/net/$IFACE/speed) |
| 59 |
echo "${IFACE}_rx.max" $((SPEED / 8 * 1000000))
|
| 60 |
echo "${IFACE}_tx.max" $((SPEED / 8 * 1000000))
|
| 61 |
echo "${IFACE}_rx.info Received traffic on the $IFACE interface. Maximum speed is ${SPEED} Mbps."
|
| 62 |
echo "${IFACE}_tx.info Transmitted traffic on the $IFACE interface. Maximum speed ${SPEED} Mbps."
|
| 63 |
fi |
| 64 |
exit 0 |
| 65 |
fi |
| 66 |
|
| 67 |
# Autorun logic |
| 68 |
running=true |
| 69 |
if [ ! -e ${cache} ]
|
| 70 |
then |
| 71 |
# no cache file |
| 72 |
running=false |
| 73 |
elif [ ! -s ${cache} ]
|
| 74 |
then |
| 75 |
# empty cache file |
| 76 |
if [ -s ${pidfile} ]
|
| 77 |
then |
| 78 |
# kill -0 will return success if this user is allowed to send |
| 79 |
# a signal to the process. This means the PID exists and |
| 80 |
# belongs to the plugin user, which should have few false |
| 81 |
# positives. |
| 82 |
if ! kill -0 $(cat ${pidfile})
|
| 83 |
then |
| 84 |
running=false |
| 85 |
fi |
| 86 |
else |
| 87 |
running=false |
| 88 |
fi |
| 89 |
fi |
| 90 |
if ! $running |
| 91 |
then |
| 92 |
$0 acquire & |
| 93 |
# wait a little so we have some data to report |
| 94 |
sleep 3 |
| 95 |
fi |
| 96 |
|
| 97 |
# Finally: Print collected values, truncate to mark spot. |
| 98 |
cat ${cache}
|
| 99 |
> ${cache}
|
| 100 |
|
| 101 |
exit 0 |
