|
| 1 | +package CloudForecast::Data::Ifpkt; |
| 2 | + |
| 3 | +use CloudForecast::Data -base; |
| 4 | +use CloudForecast::Log; |
| 5 | + |
| 6 | +rrds map { [ $_, 'COUNTER' ] } qw /inucast outucast inmcast outmcast inbcast outbcast/; |
| 7 | +graphs 'ifpkt' => 'Interface Packets'; |
| 8 | + |
| 9 | +title { |
| 10 | + my $c = shift; |
| 11 | + my $ifname = $c->args->[1] || $c->args->[0] || '0'; |
| 12 | + return "Interface Packets ($ifname)"; |
| 13 | +}; |
| 14 | + |
| 15 | +fetcher { |
| 16 | + my $c = shift; |
| 17 | + my $interface = $c->args->[0] || 0; |
| 18 | + |
| 19 | + if ( $interface !~ /^\d+$/ ) { |
| 20 | + my %interfaces = map { $_ => 1 } split /\|/, $interface; |
| 21 | +
|
| 22 | + my $ifs = $c->component('SNMP')->table( |
| 23 | + "ifTable", |
| 24 | + columns => [ |
| 25 | + qw/ifIndex ifDescr/, |
| 26 | + qw/ifInUcastPkts ifHCInUcastPkts ifOutUcastPkts ifHCOutUcastPkts |
| 27 | + ifInMulticastPkts ifHCInMulticastPkts ifOutMulticastPkts ifHCOutMulticastPkts |
| 28 | + ifInBroadcastPkts ifHCInBroadcastPkts ifOutBroadcastPkts ifHCOutBroadcastPkts/, |
| 29 | + ], |
| 30 | + ); |
| 31 | + if ( !$ifs ) { |
| 32 | + CloudForecast::Log->warn("could not get iftable"); |
| 33 | + return [ undef, undef, undef, undef, undef, undef ]; |
| 34 | + } |
| 35 | + |
| 36 | + my $if = List::Util::first { exists $interfaces{ $_->{ifDescr} } } values %{$ifs}; |
| 37 | + if ( !$if ) { |
| 38 | + CloudForecast::Log->warn("could not find network interface '$interface'"); |
| 39 | + return [ undef, undef, undef, undef, undef, undef ]; |
| 40 | + } |
| 41 | + |
| 42 | + CloudForecast::Log->debug("found network interface '$interface' with ifIndex:$if->{ifIndex}"); |
| 43 | + |
| 44 | + my $in_u = exists $if->{ifHCInUcastPkts} ? $if->{ifHCInUcastPkts} : $if->{ifInUcastPkts}; |
| 45 | + my $out_u = exists $if->{ifHCOutUcastPkts} ? $if->{ifHCOutUcastPkts} : $if->{ifOutUcastPkts}; |
| 46 | + my $in_m = exists $if->{ifHCInMulticastPkts} ? $if->{ifHCInMulticastPkts} : $if->{ifInMulticastPkts}; |
| 47 | + my $out_m = exists $if->{ifHCOutMulticastPkts} ? $if->{ifHCOutMulticastPkts} : $if->{ifOutMulticastPkts}; |
| 48 | + my $in_b = exists $if->{ifHCInBroadcastPkts} ? $if->{ifHCInBroadcastPkts} : $if->{ifInBroadcastPkts}; |
| 49 | + my $out_b = exists $if->{ifHCOutBroadcastPkts} ? $if->{ifHCOutBroadcastPkts} : $if->{ifOutBroadcastPkts}; |
| 50 | + |
| 51 | + return [ $in_u, $out_u, $in_m, $out_m, $in_b, $out_b ]; |
| 52 | + } |
| 53 | + |
| 54 | + my @map = map { [ $_, $interface ] } |
| 55 | + qw/ifInUcastPkts ifOutUcastPkts |
| 56 | + ifInMulticastPkts ifOutMulticastPkts |
| 57 | + ifInBroadcastPkts ifOutBroadcastPkts/; |
| 58 | + |
| 59 | + if ( $c->component('SNMP')->config->{version} eq '2' ) { |
| 60 | + push @map, map { [ $_, $interface ] } |
| 61 | + qw/ifHCInUcastPkts ifHCOutUcastPkts |
| 62 | + ifHCInMulticastPkts ifHCOutMulticastPkts |
| 63 | + ifHCInBroadcastPkts ifHCOutBroadcastPkts/; |
| 64 | + } |
| 65 | + |
| 66 | + my $ret = $c->component('SNMP')->get(@map); |
| 67 | + |
| 68 | + for ( my $i = 6; $i < 12; $i++ ) { |
| 69 | + if ( !defined( $ret->[$i] ) || $ret->[$i] eq '' ) { |
| 70 | + CloudForecast::Log->debug("use 32bit Packet counter"); |
| 71 | + return [ @{$ret}[ 0 .. 5 ] ]; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return [ @{$ret}[ 6 .. 11 ] ]; |
| 76 | +}; |
| 77 | + |
| 78 | +__DATA__ |
| 79 | +@@ ifpkt |
| 80 | +DEF:inucast=<%RRD%>:inucast:AVERAGE |
| 81 | +DEF:outucast=<%RRD%>:outucast:AVERAGE |
| 82 | +DEF:inmcast=<%RRD%>:inmcast:AVERAGE |
| 83 | +DEF:outmcast=<%RRD%>:outmcast:AVERAGE |
| 84 | +DEF:inbcast=<%RRD%>:inbcast:AVERAGE |
| 85 | +DEF:outbcast=<%RRD%>:outbcast:AVERAGE |
| 86 | +LINE1:inucast#00C000:InUcast |
| 87 | +GPRINT:inucast:LAST:Cur\:%7.0lf |
| 88 | +GPRINT:inucast:AVERAGE:Ave\:%7.0lf |
| 89 | +GPRINT:inucast:MAX:Max\:%7.0lf\l |
| 90 | +LINE1:outucast#0000FF:OutUcast |
| 91 | +GPRINT:outucast:LAST:Cur\:%7.0lf |
| 92 | +GPRINT:outucast:AVERAGE:Ave\:%7.0lf |
| 93 | +GPRINT:outucast:MAX:Max\:%7.0lf\l |
| 94 | +LINE1:inmcast#00C0C0:InMcast |
| 95 | +GPRINT:inmcast:LAST:Cur\:%7.0lf |
| 96 | +GPRINT:inmcast:AVERAGE:Ave\:%7.0lf |
| 97 | +GPRINT:inmcast:MAX:Max\:%7.0lf\l |
| 98 | +LINE1:outmcast#C0C000:OutMcast |
| 99 | +GPRINT:outmcast:LAST:Cur\:%7.0lf |
| 100 | +GPRINT:outmcast:AVERAGE:Ave\:%7.0lf |
| 101 | +GPRINT:outmcast:MAX:Max\:%7.0lf\l |
| 102 | +LINE1:inbcast#000000:InBcast |
| 103 | +GPRINT:inbcast:LAST:Cur\:%7.0lf |
| 104 | +GPRINT:inbcast:AVERAGE:Ave\:%7.0lf |
| 105 | +GPRINT:inbcast:MAX:Max\:%7.0lf\l |
| 106 | +LINE1:outbcast#C000C0:OutBcast |
| 107 | +GPRINT:outbcast:LAST:Cur\:%7.0lf |
| 108 | +GPRINT:outbcast:AVERAGE:Ave\:%7.0lf |
| 109 | +GPRINT:outbcast:MAX:Max\:%7.0lf\l |
| 110 | +
|
| 111 | +
|
0 commit comments