Merge pull request #1284 from shtrom/snmp__fixes

Snmp  fixes
This commit is contained in:
Lars Kruse 2022-03-11 13:17:26 +01:00 committed by GitHub
commit 3ac71f4c23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 24 deletions

View File

@ -88,8 +88,8 @@ if ($ARGV[0] and $ARGV[0] eq "config") {
if (defined $response) {
print "multigraph flash\n";
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysFlashTotalOID} * 1024) . "\n";
print "graph_title Flash disk usage\n";
print "graph_category system\n";
print "graph_title Disk usage\n";
print "graph_category disk\n";
print "graph_info This graph shows the router's flash disk usage.\n";
print "graph_order Total Used\n";
print "graph_vlabel bytes\n";
@ -103,7 +103,7 @@ if ($ARGV[0] and $ARGV[0] eq "config") {
if (defined $response) {
print "multigraph ram\n";
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotalOID} * 1024) . "\n";
print "graph_title RAM usage\n";
print "graph_title Memory usage\n";
print "graph_category system\n";
print "graph_info This graph shows the router's memory usage.\n";
print "graph_order Total Used\n";

View File

@ -33,7 +33,7 @@ reality. The stored values would need to be adjusted.
bytes to bits. Conversely, they do now need a CDEF to convert bits to bytes.
To reflect this aspect explicitely, the root graph's totals are named
recv_bits and send_bits.
`recv_bits` and `send_bits`.
=head1 CONFIGURATION
@ -45,6 +45,7 @@ configuration (shown here) will only work on insecure sites/devices:
env.community public
env.ifTypeOnly ethernetCsmacd
env.stackedRoot 1
env.stackedMax 0
In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption). But in any
@ -74,6 +75,28 @@ would normally be for VPNs. A minor horde of different interface types
are supposted, please see IANAifType-MIB (on your system or find with
Google) for a full list.
=head2 MULTIPLE INSTANCES
It is possible to run multiple instances of the plugin for the same host. This
is most useful to generate separate views for groups of ifTypes (e.g.,
ethernetCsmacd, ieee82011, l2vlan, ...).
New instances should be symlinked to the script with an underscore-separated
suffix. A matching configuration file should be present to specify the required
ifTypes (or any other relevant parameters).
$ readlink /etc/munin/plugins/snmp_192.2.0.1_if_combined_vlan
/path/to/munin-contrib/plugins/snmp/snmp__if_combined
$ sudo cat /etc/munin/plugin-conf.d/snmp_192.2.0.1_if_combined_vlan
env.ifTypeOnly l2vlan
The suffix will be appended to the graph base name, e.g.,
`snmp_<HOST>_if_combined_<SUFFIX>` will generate the `snmp_if_combined_<SUFFIX>`
multigraph and associated series for the selected `<HOST>`.
=head2 STACKED ROOT GRAPH
The `stackedRoot` option determines whether the root summary graph shows the
traffic on each interface separately, or stacks them on top of one another to
show the total traffic through the device.
@ -139,12 +162,18 @@ issue (compounded by the first) is that of wraparound. When one of the counters
wraps around, the sum jumps backwards. With a `min` set to 0, and other counters
having kept increasing, this looks like a huge increase the total counter.
Depending on the `max` (which should match the backplane bandwidth), this may
not be correctly recognised as a spurious value, just reconded as valid.
not be correctly recognised as a spurious value, just recorded as valid.
There is no clear solution to this bug at the moment, save for trying to salvage
the data after the fact. This can be done my either clipping all values beyond a
maximum (e.g., the known use of the switch, rather that its full backplane
bandwith).
As a workaround, the `stackedMax` option is available. It will be set as the max
values for the `send_bits` and `recv_bits` sum series, allowing to prevent
overshoot. It should be set to around the expected maximum given the monitored
network, rather than the sum of the theoretical maxes of the interfaces. This is
a blunt tool that is not going to be very precise, but it should get rid of the
largest outliers, keeping the graphs useful.
Barring that, it should be possible to salvage the data after the fact. This can
be done my either clipping all values beyond a maximum (e.g., the known use of
the switch, rather that its full backplane bandwith).
RANGE='[0-9.]\+e+\(0[789]\|[1-9][0-9]\)' # Anything >=1e07
rrdtool dump ${RRD_FILE} \
@ -211,6 +240,14 @@ use strict;
use Munin::Plugin;
use Munin::Plugin::SNMP;
my $scriptname='snmp_if_combined';
my @scriptname_components= split(/_/,$0);
my $instance = 'All interfaces';
if ($scriptname_components[-1] ne 'combined') {
$instance = $scriptname_components[-1];
$scriptname .= "_${instance}";
}
my $response;
my $iface;
@ -246,6 +283,10 @@ my $stackedRoot = 0;
if (exists $ENV{'stackedRoot'}) {
$stackedRoot = $ENV{'stackedRoot'};
}
my $stackedMax = 0;
if (exists $ENV{'stackedMax'}) {
$stackedMax = $ENV{'stackedMax'};
}
my $sysDescr = '1.3.6.1.2.1.1.1.0';
my $sysLocation = '1.3.6.1.2.1.1.6.0';
@ -611,8 +652,8 @@ sub do_config_root {
print <<END;
multigraph snmp_if_combined
graph_title All interfaces traffic
multigraph $scriptname
graph_title $instance traffic
graph_args --base 1000
graph_vlabel bits in (-) / out (+) per \${graph_period}
graph_category network
@ -622,8 +663,8 @@ END
print "graph_order";
my @ifs;
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
print " recv$if=snmp_if_combined.$if.recv send$if=snmp_if_combined.$if.send";
push @ifs, "snmp_if_combined.$if";
print " recv$if=$scriptname.$if.recv send$if=$scriptname.$if.send";
push @ifs, "$scriptname.$if";
}
if ($stackedRoot) {
print " recv_bits send_bits";
@ -676,11 +717,17 @@ send_bits.draw LINE1
send_bits.colour 000000
send_bits.negative recv_bits
END
if ($stackedMax > 0) {
print <<END;
recv_bits.max $stackedMax
send_bits.max $stackedMax
END
}
}
print <<END;
multigraph snmp_if_combined_err
graph_title All interfaces errors
multigraph ${scriptname}_err
graph_title $instance errors
graph_args --base 1000
graph_vlabel errors in (-) / out (+) per \${graph_period}
graph_category network
@ -688,7 +735,7 @@ END
print "graph_order";
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
print " recv$if=snmp_if_combined_err.$if.total_in send$if=snmp_if_combined_err.$if.total_out";
print " recv$if=${scriptname}_err.$if.total_in send$if=${scriptname}_err.$if.total_out";
}
print "\n";
@ -761,7 +808,7 @@ sub do_config_if {
$extrainfo .= " This is a '".$ifTypeByNum{$response}."' interface.";
print <<END;
multigraph snmp_if_combined.$if
multigraph $scriptname.$if
graph_title $alias traffic
graph_info This graph shows traffic for the \"$alias\" network interface.$extrainfo
graph_args --base 1000
@ -778,7 +825,7 @@ send.negative recv
send.min 0
END
if ( defined($speed) ) {
if ( defined($speed) && $speed > 0) {
printf("recv.max %s\nsend.max %s\n", $speed, $speed);
}
@ -787,7 +834,7 @@ END
}
print <<END;
multigraph snmp_if_combined_err.$if
multigraph ${scriptname}_err.$if
graph_title $alias errors
graph_info This graph shows errors for the \"$alias\" network interface.$extrainfo
graph_args --base 1000
@ -836,11 +883,11 @@ sub do_fetch_if {
if ($status != 1) {
# Interface is down
print <<END;
multigraph snmp_if_combined.$if
multigraph $scriptname.$if
recv.value U
send.value U
send.extinfo This interface is currently down.
multigraph snmp_if_combined_err.$if
multigraph ${scriptname}_err.$if
errors_in.value U
errors_out.value U
discards_in.value U
@ -856,7 +903,7 @@ END
my $recv;
my $send;
print "multigraph snmp_if_combined.$if\n";
print "multigraph $scriptname.$if\n";
$response = $snmpinfoX->{$if}->{ifHCInOctets} || $snmpinfo->{$if}->{ifInOctets};
$recv = defined($response) ? ($response * 8) : undef;
@ -866,7 +913,7 @@ END
$send = defined($response) ? ($response * 8) : undef;
printf("send.value %s\n", $send || "U");
print "multigraph snmp_if_combined_err.$if\n";
print "multigraph ${scriptname}_err.$if\n";
my $errors = $snmpinfo->{$if}->{ifInErrors};
my $discards = $snmpinfo->{$if}->{ifInDiscards};
@ -924,8 +971,16 @@ foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
$recv += ($recv_if || 0);
$send += ($send_if || 0);
}
if ($stackedMax > 0) {
if ($recv > $stackedMax) {
$recv = 'U';
}
if ($send > $stackedMax) {
$send = 'U';
}
}
if ($stackedRoot) {
print "multigraph snmp_if_combined\n";
print "multigraph $scriptname\n";
print "recv_bits.value $recv\n";
print "send_bits.value $send\n";
}