From 387bb863f1ac534178bbcb1c0ba6671d655ec542 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 5 Jan 2022 22:07:04 +1100 Subject: [PATCH 1/5] snmp__mikrotik: unify titles and category Signed-off-by: Olivier Mehani --- plugins/router/snmp__mikrotik | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/router/snmp__mikrotik b/plugins/router/snmp__mikrotik index 2cf1880b..b57a23a1 100755 --- a/plugins/router/snmp__mikrotik +++ b/plugins/router/snmp__mikrotik @@ -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"; From 4262dc8564fa915b6090a9709e1a44de3565db44 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 5 Jan 2022 22:51:16 +1100 Subject: [PATCH 2/5] snmp__if_combined: add support for multiple instances This allows to split the data into smaller groups, e.g., per ifType. Signed-off-by: Olivier Mehani --- plugins/snmp/snmp__if_combined | 52 ++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/plugins/snmp/snmp__if_combined b/plugins/snmp/snmp__if_combined index 6d06619a..7b6e3cb1 100755 --- a/plugins/snmp/snmp__if_combined +++ b/plugins/snmp/snmp__if_combined @@ -74,6 +74,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__if_combined_` will generate the `snmp_if_combined_` +multigraph and associated series for the selected ``. + +=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. @@ -211,6 +233,12 @@ use strict; use Munin::Plugin; use Munin::Plugin::SNMP; +my $scriptname='snmp_if_combined'; +my @scriptname_components= split(/_/,$0); +if ($scriptname_components[-1] ne 'combined') { + $scriptname .= "_${scriptname_components[-1]}"; +} + my $response; my $iface; @@ -611,7 +639,7 @@ sub do_config_root { print < $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"; @@ -679,7 +707,7 @@ END } print < $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 +789,7 @@ sub do_config_if { $extrainfo .= " This is a '".$ifTypeByNum{$response}."' interface."; print <{$if}->{ifHCInOctets} || $snmpinfo->{$if}->{ifInOctets}; $recv = defined($response) ? ($response * 8) : undef; @@ -866,7 +894,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}; @@ -925,7 +953,7 @@ foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { $send += ($send_if || 0); } if ($stackedRoot) { - print "multigraph snmp_if_combined\n"; + print "multigraph $scriptname\n"; print "recv_bits.value $recv\n"; print "send_bits.value $send\n"; } From baf24f9c94e760798e38bc7b1d5a2c4e294f34e5 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 6 Jan 2022 22:32:10 +1100 Subject: [PATCH 3/5] snmp__if_combined: don't set max speed if reported as 0 Some SNMP implementations actively report the interface speed as 0 (e.g., when disconnected). This led the plugin to report both min and max to be 0, which later confuses RRDTool, with errors such as [ERROR] Unable to create '/var/lib/munin/example.net/192.2.0.1-snmp_if_combined_vlan-37-send-d.rrd': failed to parse data source 600:0:0: min must be less than max in DS definition when trying to creates the RRDs. Ultimately, this would prevent the graph creation from suceeding with errors such as [ERROR] In RRD: Error updating /var/lib/munin/example.net/192.2.0.1-snmp_if_combined_vlan-37-send-d.rrd: opening '/var/lib/munin/example.net/192.2.0.1-snmp_if_combined_vlan-37-send-d.rrd': No such file or directory Signed-off-by: Olivier Mehani --- plugins/snmp/snmp__if_combined | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/snmp/snmp__if_combined b/plugins/snmp/snmp__if_combined index 7b6e3cb1..92105d9c 100755 --- a/plugins/snmp/snmp__if_combined +++ b/plugins/snmp/snmp__if_combined @@ -806,7 +806,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); } From b14e2347f4abddb82b143a1367760f5ea51722d8 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Mon, 17 Jan 2022 23:38:35 +1100 Subject: [PATCH 4/5] snmp__if_combined: add env.stackedMax to work around sum spikes Signed-off-by: Olivier Mehani --- plugins/snmp/snmp__if_combined | 37 ++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/plugins/snmp/snmp__if_combined b/plugins/snmp/snmp__if_combined index 92105d9c..21f261f7 100755 --- a/plugins/snmp/snmp__if_combined +++ b/plugins/snmp/snmp__if_combined @@ -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 @@ -161,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} \ @@ -274,6 +281,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'; @@ -704,6 +715,12 @@ send_bits.draw LINE1 send_bits.colour 000000 send_bits.negative recv_bits END + if ($stackedMax > 0) { + print < $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 $scriptname\n"; print "recv_bits.value $recv\n"; From ada3160e9c6744a383c2820924fcc686587c552a Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 8 Mar 2022 21:34:55 +1100 Subject: [PATCH 5/5] snmp__if_combined: use instance name in graph titles Signed-off-by: Olivier Mehani --- plugins/snmp/snmp__if_combined | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/snmp/snmp__if_combined b/plugins/snmp/snmp__if_combined index 21f261f7..7be286f5 100755 --- a/plugins/snmp/snmp__if_combined +++ b/plugins/snmp/snmp__if_combined @@ -242,8 +242,10 @@ use Munin::Plugin::SNMP; my $scriptname='snmp_if_combined'; my @scriptname_components= split(/_/,$0); +my $instance = 'All interfaces'; if ($scriptname_components[-1] ne 'combined') { - $scriptname .= "_${scriptname_components[-1]}"; + $instance = $scriptname_components[-1]; + $scriptname .= "_${instance}"; } my $response; @@ -651,7 +653,7 @@ sub do_config_root { print <