root / plugins / network / vnstat_ @ 49b79ca2
Historique | Voir | Annoter | Télécharger (1,57 ko)
| 1 | 69d3d4a5 | wandrer _KaszpiR_ | #! /bin/bash |
|---|---|---|---|
| 2 | # |
||
| 3 | # Simple munin plugin to get total traffic transferred on all network interfaces. |
||
| 4 | # Uses vnStat to keep track of the traffic. |
||
| 5 | # |
||
| 6 | # author: wandrer (wandrer@gmail.com) |
||
| 7 | # site: http://roguenoise.org/munin_plugin_vnstat |
||
| 8 | # |
||
| 9 | # If the plugin is run as root it will update the vnStat database before getting |
||
| 10 | # the stats. |
||
| 11 | # |
||
| 12 | # 2009.09.28 _KaszpiR_ |
||
| 13 | # - quick an ddirty update to support multiple interfaces, for example symlink vnstat_ to vnstat_eth0 and vnstat_eth1 |
||
| 14 | # rember to run before that vnstat -u -i eth0 and vnstat -u -i eth1 to build databases (read manual of vnstat) |
||
| 15 | # other updates of this script maybe soon |
||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | a2f35e9b | Bryce Chidester | IFACE=${0##*vnstat_}
|
| 20 | 69d3d4a5 | wandrer _KaszpiR_ | |
| 21 | |||
| 22 | # Config section |
||
| 23 | if [ "$1" = "config" ]; then |
||
| 24 | |||
| 25 | echo 'graph_title Total Traffic' |
||
| 26 | echo 'graph_args --base 1000 --lower-limit 0' |
||
| 27 | echo 'graph_vlabel Traffic' |
||
| 28 | echo 'graph_category network' |
||
| 29 | echo 'graph_info Total network traffic in bytes.' |
||
| 30 | echo 'totaltx.label Sent' |
||
| 31 | echo 'totaltx.info Total data sent.' |
||
| 32 | echo 'totaltx.cdef totaltx,1000000,*' |
||
| 33 | echo 'totalrx.label Received' |
||
| 34 | echo 'totalrx.info Total data received.' |
||
| 35 | echo 'totalrx.cdef totalrx,1000000,*' |
||
| 36 | exit 0 |
||
| 37 | |||
| 38 | fi; |
||
| 39 | |||
| 40 | |||
| 41 | # The Script |
||
| 42 | # Running as root? |
||
| 43 | if [ `whoami` = "root" ]; then |
||
| 44 | `vnstat -u` |
||
| 45 | fi; |
||
| 46 | |||
| 47 | # Grabs the totals from the database. |
||
| 48 | TOTALSRX=`vnstat --dumpdb -i $IFACE | grep 'totalrx;' | cut -d';' -f2` |
||
| 49 | TOTALSTX=`vnstat --dumpdb -i $IFACE | grep 'totaltx;' | cut -d';' -f2` |
||
| 50 | |||
| 51 | TOTALSRXMB=0 |
||
| 52 | TOTALSTXMB=0 |
||
| 53 | |||
| 54 | for TOTALRX in $TOTALSRX |
||
| 55 | do |
||
| 56 | let 'TOTALSRXMB += TOTALRX' |
||
| 57 | done |
||
| 58 | |||
| 59 | for TOTALTX in $TOTALSTX |
||
| 60 | do |
||
| 61 | let 'TOTALSTXMB += TOTALTX' |
||
| 62 | done |
||
| 63 | |||
| 64 | echo 'totalrx.value' $TOTALSRXMB |
||
| 65 | echo 'totaltx.value' $TOTALSTXMB |
||
| 66 | |||
| 67 | exit 0 |
