root / plugins / network / if1sec_ @ 1bed50bb
Historique | Voir | Annoter | Télécharger (2,24 ko)
| 1 | 208874d7 | Steve Schnepp | #! /bin/sh |
|---|---|---|---|
| 2 | |||
| 3 | 5ff3522e | Kjetil Torgrim Homme | pluginfull="$0" # full name of plugin |
| 4 | plugin="${0##*/}" # name of plugin
|
||
| 5 | 208874d7 | Steve Schnepp | pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid" |
| 6 | cache="$MUNIN_PLUGSTATE/munin.$plugin.value" |
||
| 7 | |||
| 8 | 5ff3522e | Kjetil Torgrim Homme | IFACE="${0##*/if1sec_}" # interface
|
| 9 | 208874d7 | Steve Schnepp | |
| 10 | 63d61bc5 | Steve Schnepp | if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ] |
| 11 | then |
||
| 12 | echo "# Unknown Interface : $IFACE" |
||
| 13 | exit 1 |
||
| 14 | fi |
||
| 15 | |||
| 16 | 208874d7 | Steve Schnepp | if [ "$1" = "acquire" ] |
| 17 | then |
||
| 18 | 5ff3522e | Kjetil Torgrim Homme | ( |
| 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 | 208874d7 | Steve Schnepp | fi |
| 35 | |||
| 36 | |||
| 37 | if [ "$1" = "config" ] |
||
| 38 | then |
||
| 39 | 5ff3522e | Kjetil Torgrim Homme | cat <<EOF |
| 40 | 208874d7 | Steve Schnepp | graph_title Interface 1sec stats for ${IFACE}
|
| 41 | 5ff3522e | Kjetil Torgrim Homme | graph_category network |
| 42 | graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 450d |
||
| 43 | graph_vlabel bits/sec |
||
| 44 | 208874d7 | Steve Schnepp | update_rate 1 |
| 45 | 5ff3522e | Kjetil Torgrim Homme | ${IFACE}_tx.label ${IFACE} TX bits
|
| 46 | ${IFACE}_tx.cdef ${IFACE}_tx,8,*
|
||
| 47 | 63d61bc5 | Steve Schnepp | ${IFACE}_tx.type DERIVE
|
| 48 | ${IFACE}_tx.min 0
|
||
| 49 | 5ff3522e | Kjetil Torgrim Homme | ${IFACE}_rx.label ${IFACE} RX bits
|
| 50 | ${IFACE}_rx.cdef ${IFACE}_rx,8,*
|
||
| 51 | 63d61bc5 | Steve Schnepp | ${IFACE}_rx.type DERIVE
|
| 52 | ${IFACE}_rx.min 0
|
||
| 53 | 208874d7 | Steve Schnepp | EOF |
| 54 | 5ff3522e | Kjetil Torgrim Homme | # 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 | 208874d7 | Steve Schnepp | fi |
| 66 | |||
| 67 | 5ff3522e | Kjetil Torgrim Homme | # 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 | 63d61bc5 | Steve Schnepp | cat ${cache}
|
| 99 | > ${cache}
|
||
| 100 | 208874d7 | Steve Schnepp | |
| 101 | exit 0 |
