Projet

Général

Profil

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

root / plugins / network / multibandwidth @ a1cc26f2

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

1
#!/bin/sh                                                                                                                                                                                                         
2
                                                                                                                                                                                                                  
3
. "$MUNIN_LIBDIR/plugins/plugin.sh"                                                                                                                                                                               
4
                                                                                                                                                                                                                  
5
: <<=cut                                                                                                                                                                                                          
6
                                                                                                                                                                                                                  
7
=head1 NAME                                                                                                                                                                                                       
8
                                                                                                                                                                                                                  
9
multibandwidth - Plugin to monitor the bandwidth between localhost and serveral hosts.                                                                                                                            
10
                                                                                                                                                                                                                  
11
=head1 APPLICABLE SYSTEMS                                                                                                                                                                                         
12
                                                                                                                                                                                                                  
13
All systems with “bash”, and “munin”                                                                                                                                                                              
14
                                                                                                                                                                                                                  
15
=head1 REQUIREMENTS                                                                                                                                                                                               
16
                                                                                                                                                                                                                  
17
bing installed.                                                                                                                                                                                                   
18
                                                                                                                                                                                                                  
19
You can install bing by using (Ubuntu/Debian): apt-get install bing                                                                                                                                               
20
                                                                                                                                                                                                                  
21
=head1 CONFIGURATION                                                                                                                                                                                              
22
                                                                                                                                                                                                                  
23
The following is the default configuration                                                                                                                                                                        
24
                                                                                                                                                                                                                  
25
[multibandwidth]                                                                                                                                                                                                  
26
user root                                                                                                                                                                                                         
27
env.hosts example.org example2.org example3.org                                                                                                                                                                   
28
env.samples 15                                                                                                                                                                                                    
29
env.small_packet_size 44                                                                                                                                                                                          
30
env.big_packet_size 108                                                                                                                                                                                           
31
env.max_mbps 15728640                                                                                                                                                                                             
32
                                                                                                                                                                                                                  
33
- env.hosts explanation: hostname or IP of the hosts to calculate the bandwidth.                                                                                                                                  
34
                                                                                                                                                                                                                  
35
- env.samples explanation: Reset stats after sending samples ECHO_REQUEST packets.                                                                                                                                
36

    
37
- env.small_packet_size explanation: Specifies the number of data bytes to be sent in the small
38
        packets. The default and minimum value is 44.
39

    
40
- env.big_packet_size explanation: Specifies the number of data bytes to be sent in the big
41
        packets. The default is 108. The size should be chosen so that big packet roundtrip times
42
        are long enough to be accurately measured.
43

    
44
- env.max_mbps explanation: bing have some random spikes. This variable is used to indicate
45
        the maximum value of mbps that can be recorded (in bps).
46

    
47
=head1 MAGIC MARKERS
48

    
49
#%# capabilities=autoconf
50

    
51
=head1 VERSION
52

    
53
1.1.17
54

    
55
=head1 AUTHOR
56

    
57
Jose Manuel Febrer Cortés <https://www.linkedin.com/in/jfebrer/>
58
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/>
59

    
60
=head1 LICENSE
61

    
62
GPLv2
63

    
64
=cut
65

    
66

    
67

    
68
case $1 in
69
   config)
70
                echo graph_title MultiBandwidth
71
                echo 'graph_vlabel bps'
72
                echo 'graph_args --base 1024 -l 0'
73
                echo 'graph_scale yes'
74
                echo 'graph_category network'
75
                echo 'graph_info This graph shows the bandwidth between localhost and serveral hosts'
76
                for host in $hosts; do
77
                        fieldname="host_$(clean_fieldname "$host")"
78
                        echo "$fieldname.label $host"
79
                        echo "$fieldname.draw LINE2"
80
                        echo "$fieldname.info Bandwidth statistics for $host"
81
                done
82
        exit 0;;
83
    autoconf)
84
                if command -v bing >/dev/null 2>&1; then
85
                        echo 'yes'
86
                        exit 0;
87
                else
88
                        echo 'no (bing not installed)'
89
                        exit 0;
90
                fi
91

    
92
esac
93

    
94

    
95
#Calculating the bandwidth
96
for host in $hosts; do
97
        fieldname="host_$(clean_fieldname "$host")"
98
        printf "$fieldname.value ";
99

    
100
        SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \
101
                |grep "estimated link" -A 2 \
102
                | grep bps \
103
                | awk '{print $2}' \
104
                | cut -d "b" -f1)
105

    
106
        if (echo "$SPEED" | grep -q "M"); then
107
                VALUE=`echo "$SPEED" | sed 's/.$//'`
108
                RATE=`echo "$VALUE * 1048576" | bc -l`
109

    
110
                if [ $(echo "$RATE" >= "$max_mbps" | bc >/dev/null && echo "no" || echo "yes") = "yes" ]; then
111
                        echo "$max_mbps"
112
                else
113
                        echo "$RATE"
114
                fi
115
        elif (echo "$SPEED" | grep -q "K"); then
116
                VALUE=`echo "$SPEED" | sed 's/.$//'`
117
                echo "$VALUE * 1024" | bc -l
118
        elif (echo "$SPEED" | grep -q "G"); then
119
                VALUE=`echo "$SPEED" | sed 's/.$//'`
120
                echo "$VALUE * 1073742000" | bc -l
121
        else
122
                echo "Error: no data (timeout)" >&2
123
        fi
124
done