Projet

Général

Profil

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

root / plugins / network / multibandwidth @ 17f78427

Historique | Voir | Annoter | Télécharger (3,65 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 "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
- env.hosts: space separated list of hostnames or IPs of the hosts to calculate the bandwidth.
35
        This setting is required.
36

    
37
- env.samples: Reset stats after sending this number of ECHO_REQUEST packets.
38
        Defaults to 15 samples.
39

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

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

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

    
51
=head1 MAGIC MARKERS
52

    
53
#%# capabilities=autoconf
54

    
55
=head1 VERSION
56

    
57
1.1.17
58

    
59
=head1 AUTHOR
60

    
61
Jose Manuel Febrer Cortés <https://www.linkedin.com/in/jfebrer/>
62
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/>
63

    
64
=head1 LICENSE
65

    
66
GPLv2
67

    
68
=cut
69

    
70

    
71
hosts=${hosts:-}
72
samples=${samples:-15}
73
small_packet_size=${small_packet_size:-44}
74
big_packet_size=${big_packet_size:-108}
75
max_valid_bps=${max_valid_bps:-15728640}
76

    
77

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

    
104

    
105
# Calculating the bandwidth
106
for host in $hosts; do
107
        fieldname="host_$(clean_fieldname "$host")"
108

    
109
        SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \
110
                | grep "estimated link" -A 2 \
111
                | grep bps \
112
                | awk '{print $2}' \
113
                | cut -d "b" -f1)
114

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