root / plugins / network / if1sec_ @ 7dcf9569
Historique | Voir | Annoter | Télécharger (1,51 ko)
| 1 |
#! /bin/sh |
|---|---|
| 2 |
# Currently the plugin does *not* autostart |
| 3 |
# |
| 4 |
# It has to be launched via rc.d : |
| 5 |
# munin-run if1sec_eth0 acquire |
| 6 |
|
| 7 |
pluginfull="$0" # full name of plugin |
| 8 |
plugin="${0##*/}" # name of plugin
|
| 9 |
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid" |
| 10 |
cache="$MUNIN_PLUGSTATE/munin.$plugin.value" |
| 11 |
|
| 12 |
IFACE="${0##*/if1sec_}" # interface
|
| 13 |
|
| 14 |
if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ] |
| 15 |
then |
| 16 |
echo "# Unknown Interface : $IFACE" |
| 17 |
exit 1 |
| 18 |
fi |
| 19 |
|
| 20 |
if [ "$1" = "acquire" ] |
| 21 |
then |
| 22 |
( |
| 23 |
while sleep 1 |
| 24 |
do |
| 25 |
echo $( |
| 26 |
date +%s |
| 27 |
cat /sys/class/net/$IFACE/statistics/tx_bytes |
| 28 |
cat /sys/class/net/$IFACE/statistics/rx_bytes |
| 29 |
) |
| 30 |
done | awk "{
|
| 31 |
print \"${IFACE}_tx.value \" \$1 \":\" \$2;
|
| 32 |
print \"${IFACE}_rx.value \" \$1 \":\" \$3;
|
| 33 |
system(\"\"); |
| 34 |
}" >> $cache |
| 35 |
) & |
| 36 |
echo $! > $pidfile |
| 37 |
exit 0 |
| 38 |
fi |
| 39 |
|
| 40 |
|
| 41 |
if [ "$1" = "config" ] |
| 42 |
then |
| 43 |
cat <<EOF |
| 44 |
graph_title Interface 1sec stats for ${IFACE}
|
| 45 |
graph_category 1sec::network |
| 46 |
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y |
| 47 |
graph_vlabel Bytes |
| 48 |
update_rate 1 |
| 49 |
${IFACE}_tx.label ${IFACE} TX bytes
|
| 50 |
${IFACE}_tx.type DERIVE
|
| 51 |
${IFACE}_tx.min 0
|
| 52 |
${IFACE}_rx.label ${IFACE} RX bytes
|
| 53 |
${IFACE}_rx.type DERIVE
|
| 54 |
${IFACE}_rx.min 0
|
| 55 |
EOF |
| 56 |
exit 0 |
| 57 |
fi |
| 58 |
|
| 59 |
# values |
| 60 |
cat ${cache}
|
| 61 |
> ${cache}
|
| 62 |
|
| 63 |
exit 0 |
