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 1ae4ac09 Jose Manuel Febrer Cortés
#!/bin/sh
2
3
. "$MUNIN_LIBDIR/plugins/plugin.sh"
4
5
: <<=cut
6
7
=head1 NAME
8
9 8713eb37 Lars Kruse
multibandwidth - Plugin to monitor the bandwidth between localhost and several hosts.
10 1ae4ac09 Jose Manuel Febrer Cortés
11
=head1 APPLICABLE SYSTEMS
12
13 14436e80 Lars Kruse
All systems with "bing" installed.
14 1ae4ac09 Jose Manuel Febrer Cortés
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 5fb2e02e Lars Kruse
The following example configuration shows all settings. Only "hosts" is required for
24
minimal configuration.
25 1ae4ac09 Jose Manuel Febrer Cortés
26 09b88141 Lars Kruse
 [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 5fb2e02e Lars Kruse
        This setting is required.
38 1ae4ac09 Jose Manuel Febrer Cortés
39 09b88141 Lars Kruse
=item env.samples: Reset stats after sending this number of ECHO_REQUEST packets.
40 5fb2e02e Lars Kruse
        Defaults to 15 samples.
41 26e9009d Jose Manuel Febrer Cortés
42 09b88141 Lars Kruse
=item env.small_packet_size: Specifies the number of data bytes to be sent in the small
43 f679a922 Jose Manuel Febrer Cortés
        packets. The default and minimum value is 44.
44 26e9009d Jose Manuel Febrer Cortés
45 09b88141 Lars Kruse
=item env.big_packet_size: Specifies the number of data bytes to be sent in the big
46 f679a922 Jose Manuel Febrer Cortés
        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 26e9009d Jose Manuel Febrer Cortés
49 09b88141 Lars Kruse
=item env.max_valid_bps: bing have some random spikes. This variable is used to indicate
50 a1cc26f2 Jose Manuel Febrer Cortés
        the maximum value of mbps that can be recorded (in bps).
51 5fb2e02e Lars Kruse
        Defaults to the empty string (no validity check).
52 26e9009d Jose Manuel Febrer Cortés
53 09b88141 Lars Kruse
=back
54
55
56 26e9009d Jose Manuel Febrer Cortés
=head1 MAGIC MARKERS
57
58 09b88141 Lars Kruse
 #%# capabilities=autoconf
59 26e9009d Jose Manuel Febrer Cortés
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 09b88141 Lars Kruse
68 f679a922 Jose Manuel Febrer Cortés
Marco Bertola’s help <https://www.linkedin.com/in/bertolamarco/>
69 26e9009d Jose Manuel Febrer Cortés
70
=head1 LICENSE
71
72
GPLv2
73
74
=cut
75
76
77 5fb2e02e Lars Kruse
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 26e9009d Jose Manuel Febrer Cortés
84
case $1 in
85
   config)
86 ecc6e30d Lars Kruse
        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 8713eb37 Lars Kruse
        echo 'graph_info This graph shows the bandwidth between localhost and several hosts'
92 ecc6e30d Lars Kruse
        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 26e9009d Jose Manuel Febrer Cortés
    autoconf)
101 ecc6e30d Lars Kruse
        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 26e9009d Jose Manuel Febrer Cortés
esac
109
110
111 ecc6e30d Lars Kruse
# Calculating the bandwidth
112 26e9009d Jose Manuel Febrer Cortés
for host in $hosts; do
113 1bed50bb Jose Manuel Febrer Cortés
        fieldname="host_$(clean_fieldname "$host")"
114 f679a922 Jose Manuel Febrer Cortés
115
        SPEED=$(timeout 6 bing localhost "$host" -n -c 1 -e "$samples" -s "$small_packet_size" -S "$big_packet_size" 2>/dev/null \
116 ecc6e30d Lars Kruse
                | grep "estimated link" -A 2 \
117 f679a922 Jose Manuel Febrer Cortés
                | grep bps \
118
                | awk '{print $2}' \
119
                | cut -d "b" -f1)
120
121 49aecf4e Lars Kruse
        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 f679a922 Jose Manuel Febrer Cortés
        else
128 ade6f5f2 Lars Kruse
                RATE="U"
129 1bed50bb Jose Manuel Febrer Cortés
                echo "Error: no data (timeout)" >&2
130 f679a922 Jose Manuel Febrer Cortés
        fi
131 580a39ed Lars Kruse
        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 49aecf4e Lars Kruse
        fi
135
        echo "${fieldname}.value $RATE"
136 26e9009d Jose Manuel Febrer Cortés
done