From 4262dc8564fa915b6090a9709e1a44de3565db44 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 5 Jan 2022 22:51:16 +1100 Subject: [PATCH] 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"; }