Projet

Général

Profil

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

root / plugins / network / multibandwidth @ 09b88141

Historique | Voir | Annoter | Télécharger (3,69 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 several hosts.
10

    
11
=head1 APPLICABLE SYSTEMS
12

    
13
All systems with "bing" installed.
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 example configuration shows all settings. Only "hosts" is required for
24
minimal configuration.
25

    
26
 [multibandwidth]
27
 user root
28
 env.hosts example.org example2.org example3.org
29
 env.samples 15
30
 env.small_packet_size 44
31
 env.big_packet_size 108
32
 env.max_valid_bps 15728640
33

    
34
=over 4
35

    
36
=item env.hosts: space separated list of hostnames or IPs of the hosts to calculate the bandwidth.
37
        This setting is required.
38

    
39
=item env.samples: Reset stats after sending this number of ECHO_REQUEST packets.
40
        Defaults to 15 samples.
41

    
42
=item env.small_packet_size: Specifies the number of data bytes to be sent in the small
43
        packets. The default and minimum value is 44.
44

    
45
=item env.big_packet_size: Specifies the number of data bytes to be sent in the big
46
        packets. The default is 108. The size should be chosen so that big packet roundtrip times
47
        are long enough to be accurately measured.
48

    
49
=item env.max_valid_bps: bing have some random spikes. This variable is used to indicate
50
        the maximum value of mbps that can be recorded (in bps).
51
        Defaults to the empty string (no validity check).
52

    
53
=back
54

    
55

    
56
=head1 MAGIC MARKERS
57

    
58
 #%# capabilities=autoconf
59

    
60
=head1 VERSION
61

    
62
1.1.17
63

    
64
=head1 AUTHOR
65

    
66
Jose Manuel Febrer Cortés <https://www.linkedin.com/in/jfebrer/>
67

    
68
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/>
69

    
70
=head1 LICENSE
71

    
72
GPLv2
73

    
74
=cut
75

    
76

    
77
hosts=${hosts:-}
78
samples=${samples:-15}
79
small_packet_size=${small_packet_size:-44}
80
big_packet_size=${big_packet_size:-108}
81
max_valid_bps=${max_valid_bps:-15728640}
82

    
83

    
84
case $1 in
85
   config)
86
        echo graph_title MultiBandwidth
87
        echo 'graph_vlabel bps'
88
        echo 'graph_args --base 1024 -l 0'
89
        echo 'graph_scale yes'
90
        echo 'graph_category network'
91
        echo 'graph_info This graph shows the bandwidth between localhost and several hosts'
92
        for host in $hosts; do
93
                fieldname="host_$(clean_fieldname "$host")"
94
                echo "$fieldname.label $host"
95
                echo "$fieldname.draw LINE2"
96
                echo "$fieldname.info Bandwidth statistics for $host"
97
        done
98
        exit 0
99
        ;;
100
    autoconf)
101
        if command -v bing 2>/dev/null; then
102
                echo 'yes'
103
        else
104
                echo 'no (bing not installed)'
105
        fi
106
        exit 0
107
        ;;
108
esac
109

    
110

    
111
# Calculating the bandwidth
112
for host in $hosts; do
113
        fieldname="host_$(clean_fieldname "$host")"
114

    
115
        SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \
116
                | grep "estimated link" -A 2 \
117
                | grep bps \
118
                | awk '{print $2}' \
119
                | cut -d "b" -f1)
120

    
121
        if echo "$SPEED" | grep -q "M"; then
122
                RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024 * 1024); }')
123
        elif echo "$SPEED" | grep -q "K"; then
124
                RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024); }')
125
        elif echo "$SPEED" | grep -q "G"; then
126
                RATE=$(echo "$SPEED" | awk '{ print int($1 * 1024 * 1024 * 1024); }')
127
        else
128
                RATE="U"
129
                echo "Error: no data (timeout)" >&2
130
        fi
131
        if [ -n "$max_valid_bps" ] && [ "$RATE" -gt "$max_valid_bps" ]; then
132
                # the value is outside of the allowed range; discard it
133
                RATE="U"
134
        fi
135
        echo "${fieldname}.value $RATE"
136
done