Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / vnstat @ dd4afac8

Historique | Voir | Annoter | Télécharger (1,24 ko)

1
#! /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

    
13

    
14
# Config section
15
if [ "$1" = "config" ]; then
16

    
17
	echo 'graph_title Total Traffic'
18
	echo 'graph_args --base 1000 --lower-limit 0'
19
	echo 'graph_vlabel Traffic'
20
	echo 'graph_category network'
21
	echo 'graph_info Total network traffic in bytes.'
22
	echo 'totaltx.label Sent'
23
	echo 'totaltx.info Total data sent.'
24
	echo 'totaltx.cdef totaltx,1000000,*'
25
	echo 'totalrx.label Received'
26
	echo 'totalrx.info Total data received.'
27
	echo 'totalrx.cdef totalrx,1000000,*'
28
	exit 0
29
	
30
fi;
31

    
32

    
33
# The Script
34

    
35
# Running as root?
36
if [ `whoami` = "root" ]; then
37
	`vnstat -u`
38
fi;
39

    
40
# Grabs the totals from the database.
41
TOTALSRX=`vnstat --dumpdb | grep 'totalrx;' | cut -d';' -f2`
42
TOTALSTX=`vnstat --dumpdb | grep 'totaltx;' | cut -d';' -f2`
43

    
44
TOTALSRXMB=0
45
TOTALSTXMB=0
46

    
47
for TOTALRX in $TOTALSRX
48
do
49
	let 'TOTALSRXMB += TOTALRX'
50
done
51

    
52
for TOTALTX in $TOTALSTX
53
do
54
	let 'TOTALSTXMB += TOTALTX'
55
done
56

    
57
echo 'totalrx.value' $TOTALSRXMB
58
echo 'totaltx.value' $TOTALSTXMB
59

    
60
exit 0