1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

[snmp__if_combined] Reindent

This commit is contained in:
Olivier Mehani 2021-07-20 10:51:25 +10:00
parent 6ac458ace1
commit ecb1d34814

View file

@ -8,25 +8,29 @@ snmp__if_combined - SNMP card plugin to monitor the network interfaces of any ne
=head1 APPLICABLE SYSTEMS =head1 APPLICABLE SYSTEMS
Any SNMP capable networked computer equipment. Using a command such Any SNMP capable networked computer equipment. Using a command such
as "munin-node-configure --snmp switch.langfeldt.net --snmpversion 2c as
--snmpcommunity public | sh -x" should auto-detect all applicable
interfaces. On a typical switch you will get one plugin pr. ethernet munin-node-configure --snmp switch.langfeldt.net --snmpversion 2c --snmpcommunity public | sh -x
port. On a router you might get one plugin per VLAN interface.
should auto-detect all applicable interfaces. On a typical switch you will get
one plugin pr. ethernet port. On a router you might get one plugin per VLAN
interface.
=head2 NOTABLE DIFFERENCE WITH SNMP__IF_MULTI =head2 NOTABLE DIFFERENCE WITH SNMP__IF_MULTI
The smnp__if_multi plugin records data in _bytes_ per second, and shows The `smnp__if_multi` plugin records data in _bytes_ per second, and shows them
them as bps by using CDEFs when graphing. This plugin performs the as bps by using CDEFs when graphing. This plugin performs the multiplication
multiplication upon reporting the value, and therefore doesn't have a upon reporting the value, and therefore doesn't have a CDEF in the graphing
CDEF in the graphing path. path.
This is important when migration from snmp__if_multi, for at least two aspects: This is important when migration from `snmp__if_multi`, for at least two
aspects:
- Reusing RRDs: it is not possible to just rename the old RRD files from - Reusing RRDs: it is not possible to just rename the old RRD files from
smnp__if_multi, as historical data will be graphed as 8 times smaller than in `smnp__if_multi`, as historical data will be graphed as 8 times smaller than in
reality. The stored values would need to be adjusted. reality. The stored values would need to be adjusted.
- Data loaning: borrowing graphs no longer need to include a CDEF to convert - Data loaning: borrowing graphs no longer need to include a CDEF to convert
bytes to bits. Conversely, they do now need a CDEF to convert bits to bytes. 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 To reflect this aspect explicitely, the root graph's totals are named
recv_bits and send_bits. recv_bits and send_bits.
@ -37,10 +41,10 @@ As a rule SNMP plugins need site specific configuration. The default
configuration (shown here) will only work on insecure sites/devices: configuration (shown here) will only work on insecure sites/devices:
[snmp_*] [snmp_*]
env.version 2 env.version 2
env.community public env.community public
env.ifTypeOnly ethernetCsmacd env.ifTypeOnly ethernetCsmacd
env.stackedRoot 1 env.stackedRoot 1
In general SNMP is not very secure at all unless you use SNMP version In general SNMP is not very secure at all unless you use SNMP version
3 which supports authentication and privacy (encryption). But in any 3 which supports authentication and privacy (encryption). But in any
@ -70,9 +74,9 @@ would normally be for VPNs. A minor horde of different interface types
are supposted, please see IANAifType-MIB (on your system or find with are supposted, please see IANAifType-MIB (on your system or find with
Google) for a full list. Google) for a full list.
The stackedRoot option determines whether the root summary graph shows the traffic The `stackedRoot` option determines whether the root summary graph shows the
on each interface separately, or stacks them on top of one another to show the traffic on each interface separately, or stacks them on top of one another to
total traffic through the device. show the total traffic through the device.
=head1 INTERPRETATION =head1 INTERPRETATION
@ -85,7 +89,7 @@ two additional series are calculated to show the total usage of the device.
Those series are useful for loaning into higher-level summary graphs (but see Those series are useful for loaning into higher-level summary graphs (but see
BUGS below). BUGS below).
Sub-graphs are created, one per interface, akin to snmp__if_multi Sub-graphs are created, one per interface, akin to `snmp__if_multi`
plugin. plugin.
=head1 MIB INFORMATION =head1 MIB INFORMATION
@ -126,7 +130,7 @@ Should support indexing by
When using the `stackedRoot` option, the total lines (`send_bits` and When using the `stackedRoot` option, the total lines (`send_bits` and
`recv_bits`) may sometimes jump to nonsensical values. This is a bug shared with `recv_bits`) may sometimes jump to nonsensical values. This is a bug shared with
the original snmp__if_multi. the original `snmp__if_multi`.
This seems to be due to the way those series are calculated, by summing the This seems to be due to the way those series are calculated, by summing the
current values of the other counters. The first issue is that of summing 64-bit current values of the other counters. The first issue is that of summing 64-bit
@ -234,8 +238,8 @@ my $iface;
# .1.3.6.1.2.1.31.1.1.1.10. Counter64 ifHCOutOctets # .1.3.6.1.2.1.31.1.1.1.10. Counter64 ifHCOutOctets
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") { if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
print "require 1.3.6.1.2.1.2.2.1.1.\n"; print "require 1.3.6.1.2.1.2.2.1.1.\n";
exit 0; exit 0;
} }
my $stackedRoot = 0; my $stackedRoot = 0;
@ -496,7 +500,7 @@ my %ifTypes = (
x86Laps => 242, x86Laps => 242,
wwanPP => 243, wwanPP => 243,
wwanPP2 => 244 wwanPP2 => 244
); );
my %ifTypeByNum = map { $ifTypes{$_} => $_; } keys %ifTypes; my %ifTypeByNum = map { $ifTypes{$_} => $_; } keys %ifTypes;
@ -510,33 +514,33 @@ sub do_collect {
my $session = Munin::Plugin::SNMP->session(); my $session = Munin::Plugin::SNMP->session();
$snmpinfo = $session->get_hash( $snmpinfo = $session->get_hash(
-baseoid => $ifOIDBase, -baseoid => $ifOIDBase,
-cols => -cols => {
{ 2 => 'ifDescr', 2 => 'ifDescr',
# Type: See above # Type: See above
3 => 'ifType', 3 => 'ifType',
5 => 'ifSpeed', 5 => 'ifSpeed',
# Oper: 1) up 2) down 3) testing # Oper: 1) up 2) down 3) testing
# 4) unknown, 5) dormant 6) not present # 4) unknown, 5) dormant 6) not present
# 7) lowerLayerDown # 7) lowerLayerDown
8 => 'ifOperStatus', 8 => 'ifOperStatus',
10 => 'ifInOctets', 10 => 'ifInOctets',
13 => 'ifInDiscards', 13 => 'ifInDiscards',
14 => 'ifInErrors', 14 => 'ifInErrors',
16 => 'ifOutOctets', 16 => 'ifOutOctets',
19 => 'ifOutDiscards', 19 => 'ifOutDiscards',
20 => 'ifOutErrors', 20 => 'ifOutErrors',
}); });
# ifXEntry - SNMP v2 and up only - on some devices # ifXEntry - SNMP v2 and up only - on some devices
$snmpinfoX = $session->get_hash( $snmpinfoX = $session->get_hash(
-baseoid => $ifv2OIDBase, -baseoid => $ifv2OIDBase,
-cols => -cols => {
{ 6 => 'ifHCInOctets', 6 => 'ifHCInOctets',
10 => 'ifHCOutOctets', 10 => 'ifHCOutOctets',
15 => 'ifHighSpeed', 15 => 'ifHighSpeed',
18 => 'ifAlias', 18 => 'ifAlias',
}); });
} }
@ -547,27 +551,27 @@ sub do_preprocess_if {
my $response = $snmpinfo->{$if}->{ifType} || 1; my $response = $snmpinfo->{$if}->{ifType} || 1;
if (defined($mediatype)) { if (defined($mediatype)) {
if (defined($mediatype->{$response})) { if (defined($mediatype->{$response})) {
# This is one of the interesting media types # This is one of the interesting media types
} else { } else {
# This media type is not interesting. Remove. # This media type is not interesting. Remove.
delete $snmpinfo->{$if} if exists $snmpinfo->{$if}; delete $snmpinfo->{$if} if exists $snmpinfo->{$if};
delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if}; delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if};
return; return;
} }
} }
if (defined ($response = $snmpinfo->{$if}->{ifOperStatus})) { if (defined ($response = $snmpinfo->{$if}->{ifOperStatus})) {
# 1 = up, 2 = down, 7 = lowerLayerDown # 1 = up, 2 = down, 7 = lowerLayerDown
if ($response == 2 or $response == 7) { if ($response == 2 or $response == 7) {
# Fold recognized down states into one. # Fold recognized down states into one.
$response = $snmpinfo->{$if}->{ifOperStatus} = 2; $response = $snmpinfo->{$if}->{ifOperStatus} = 2;
} elsif ($response != 1) { } elsif ($response != 1) {
# This interface is fishy, remove and forget. # This interface is fishy, remove and forget.
delete $snmpinfo->{$if} if exists $snmpinfo->{$if}; delete $snmpinfo->{$if} if exists $snmpinfo->{$if};
delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if}; delete $snmpinfoX->{$if} if exists $snmpinfoX->{$if};
return; return;
} }
} }
} }
@ -576,7 +580,7 @@ sub do_preprocess {
my $mediatypes = 'ALL'; my $mediatypes = 'ALL';
if (exists( $ENV{'ifTypeOnly'} )) { if (exists( $ENV{'ifTypeOnly'} )) {
$mediatypes = $ENV{'ifTypeOnly'}; $mediatypes = $ENV{'ifTypeOnly'};
} }
my @mediatypes = split(/[ ,]+/,$mediatypes); my @mediatypes = split(/[ ,]+/,$mediatypes);
@ -585,19 +589,19 @@ sub do_preprocess {
my $mediatype={}; my $mediatype={};
if ($mediatypes eq 'ALL') { if ($mediatypes eq 'ALL') {
$mediatype = undef; $mediatype = undef;
} else { } else {
foreach my $type (@mediatypes) { foreach my $type (@mediatypes) {
if (exists($ifTypes{$type})) { if (exists($ifTypes{$type})) {
$mediatype->{$ifTypes{$type}} = 1; $mediatype->{$ifTypes{$type}} = 1;
} else { } else {
die "Unknown media type '$type' specified in ifTypeOnly\n"; die "Unknown media type '$type' specified in ifTypeOnly\n";
} }
} }
} }
foreach my $if (keys %{$snmpinfo}) { foreach my $if (keys %{$snmpinfo}) {
do_preprocess_if($mediatype, $if); do_preprocess_if($mediatype, $if);
} }
} }
@ -618,8 +622,8 @@ END
print "graph_order"; print "graph_order";
my @ifs; my @ifs;
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
print " recv$if=snmp_if_combined.$if.recv send$if=snmp_if_combined.$if.send"; print " recv$if=snmp_if_combined.$if.recv send$if=snmp_if_combined.$if.send";
push @ifs, "snmp_if_combined.$if"; push @ifs, "snmp_if_combined.$if";
} }
if ($stackedRoot) { if ($stackedRoot) {
print " recv_bits send_bits"; print " recv_bits send_bits";
@ -629,23 +633,23 @@ END
# XXX: For some reason, Munin doesn't resolve AREASTACK properly in this case... # XXX: For some reason, Munin doesn't resolve AREASTACK properly in this case...
my $area_or_stack = "AREA"; my $area_or_stack = "AREA";
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if"; my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if";
if (! ($alias =~ /\d+/) ) { if (! ($alias =~ /\d+/) ) {
# If there are no numbers in the $alias add the if index # If there are no numbers in the $alias add the if index
$alias .=" (if $if)"; $alias .=" (if $if)";
} }
print <<END; print <<END;
recv$if.label $alias recv$if.label $alias
recv$if.graph no recv$if.graph no
send$if.label $alias send$if.label $alias
send$if.negative recv$if send$if.negative recv$if
END END
if ($stackedRoot) { if ($stackedRoot) {
print "send$if.draw $area_or_stack\n"; print "send$if.draw $area_or_stack\n";
$area_or_stack = "STACK"; $area_or_stack = "STACK";
} }
} }
if ($stackedRoot) { if ($stackedRoot) {
@ -684,19 +688,19 @@ END
print "graph_order"; print "graph_order";
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { 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=snmp_if_combined_err.$if.total_in send$if=snmp_if_combined_err.$if.total_out";
} }
print "\n"; print "\n";
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if"; my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if";
if (! ($alias =~ /\d+/) ) { if (! ($alias =~ /\d+/) ) {
# If there are no numbers in the $alias add the if index # If there are no numbers in the $alias add the if index
$alias .=" (if $if)"; $alias .=" (if $if)";
} }
print <<END; print <<END;
recv$if.label $alias recv$if.label $alias
recv$if.graph no recv$if.graph no
send$if.label $alias send$if.label $alias
@ -711,8 +715,8 @@ sub do_config_if {
my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if"; my $alias = $snmpinfoX->{$if}->{ifAlias} || $snmpinfo->{$if}->{ifDescr} || "Interface $if";
if (! ($alias =~ /\d+/) ) { if (! ($alias =~ /\d+/) ) {
# If there are no numbers in the $alias add the if index # If there are no numbers in the $alias add the if index
$alias .=" (if $if)"; $alias .=" (if $if)";
} }
my $warn = undef; my $warn = undef;
@ -721,28 +725,28 @@ sub do_config_if {
my $extrainfo=""; my $extrainfo="";
if (defined ($snmpinfoX->{$if}->{ifHCInOctets})) { if (defined ($snmpinfoX->{$if}->{ifHCInOctets})) {
# If we get an answer at the 64 bit OID then this switch # If we get an answer at the 64 bit OID then this switch
# supports the extended MIB # supports the extended MIB
$extrainfo .= " This switch supports 64 bit byte counters and these are used by this plugin."; $extrainfo .= " This switch supports 64 bit byte counters and these are used by this plugin.";
} else { } else {
# If not we only have a 32 bit counter and are lost. # If not we only have a 32 bit counter and are lost.
$extrainfo .= " NOTE! This switch supports only 32 bit byte counters which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that for interfaces where much traffic is sent this plugin will report false throughputs and cannot be trusted."; $extrainfo .= " NOTE! This switch supports only 32 bit byte counters which makes the plugin unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that for interfaces where much traffic is sent this plugin will report false throughputs and cannot be trusted.";
# unless perhaps the operator can get us snmp version 2c or 3? # unless perhaps the operator can get us snmp version 2c or 3?
$extrainfo .= " I notice that you use SNMP version 1 which does not support 64 bit quantities. You may get better results if you switch to SNMP version 2c or 3. Please refer to the plugin documentation." $extrainfo .= " I notice that you use SNMP version 1 which does not support 64 bit quantities. You may get better results if you switch to SNMP version 2c or 3. Please refer to the plugin documentation."
if $version == 1; if $version == 1;
} }
if (defined ($speed = $snmpinfoX->{$if}->{ifHighSpeed}) and $speed) { if (defined ($speed = $snmpinfoX->{$if}->{ifHighSpeed}) and $speed) {
# Speed in 1,000,000 bits per second # Speed in 1,000,000 bits per second
$speed = $speed * 1000000; $speed = $speed * 1000000;
$warn = $speed / 75 * 100; $warn = $speed / 75 * 100;
my $textspeed = scaleNumber($speed,'bps','', my $textspeed = scaleNumber($speed,'bps','',
'The interface speed is %.1f%s%s.'); 'The interface speed is %.1f%s%s.');
$extrainfo .= ' '.$textspeed if $textspeed; $extrainfo .= ' '.$textspeed if $textspeed;
} elsif (defined ($speed = $snmpinfo->{$if}->{ifSpeed}) and $speed) { } elsif (defined ($speed = $snmpinfo->{$if}->{ifSpeed}) and $speed) {
# Speed in bits pr. second # Speed in bits pr. second
$warn = $speed*100/75; $warn = $speed*100/75;
@ -775,11 +779,11 @@ send.min 0
END END
if ( defined($speed) ) { if ( defined($speed) ) {
printf("recv.max %s\nsend.max %s\n", $speed, $speed); printf("recv.max %s\nsend.max %s\n", $speed, $speed);
} }
if ( defined($warn) ) { if ( defined($warn) ) {
printf("recv.warning %s\nsend.warning %s\n", $warn, $warn); printf("recv.warning %s\nsend.warning %s\n", $warn, $warn);
} }
print <<END; print <<END;
@ -867,22 +871,22 @@ END
my $errors = $snmpinfo->{$if}->{ifInErrors}; my $errors = $snmpinfo->{$if}->{ifInErrors};
my $discards = $snmpinfo->{$if}->{ifInDiscards}; my $discards = $snmpinfo->{$if}->{ifInDiscards};
printf("errors_in.value %s\n". printf("errors_in.value %s\n".
"discards_in.value %s\n". "discards_in.value %s\n".
"total_in.value %s\n", "total_in.value %s\n",
$errors || "U", $errors || "U",
$discards || "U", $discards || "U",
($errors || 0) + ($discards || 0) ($errors || 0) + ($discards || 0)
); );
$errors = $snmpinfo->{$if}->{ifOutErrors}; $errors = $snmpinfo->{$if}->{ifOutErrors};
$discards = $snmpinfo->{$if}->{ifOutDiscards}; $discards = $snmpinfo->{$if}->{ifOutDiscards};
printf("errors_out.value %s\n". printf("errors_out.value %s\n".
"discards_out.value %s\n". "discards_out.value %s\n".
"total_out.value %s\n", "total_out.value %s\n",
$errors || "U", $errors || "U",
$discards || "U", $discards || "U",
($errors || 0) + ($discards || 0) ($errors || 0) + ($discards || 0)
); );
return ($recv, $send); return ($recv, $send);
} }
@ -894,7 +898,7 @@ sub do_config {
print "host_name $host\n" unless $host eq 'localhost'; print "host_name $host\n" unless $host eq 'localhost';
foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) { foreach my $if (sort {$a <=> $b} keys %{$snmpinfo}) {
do_config_if($host,$version,$if); do_config_if($host,$version,$if);
} }
do_config_root($host,$version); do_config_root($host,$version);