Created
October 13, 2010 10:38
-
-
Save kazeburo/623805 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CloudForecast::Data::Ucastpkts; | |
use CloudForecast::Data -base; | |
use CloudForecast::Log; | |
rrds map { [ $_, 'COUNTER' ] } qw /in out/; | |
graphs 'traffic' => 'Packets per sec'; | |
title { | |
my $c = shift; | |
my $ifname = $c->args->[1] || $c->args->[0] || '0'; return "Unicast Packets ($ifname)"; | |
}; | |
fetcher { | |
my $c = shift; | |
my $interface = $c->args->[0] || 0; | |
if ( $interface !~ /^\d+$/ ) { | |
my %interfaces = map { $_ => 1 } split /\|/, $interface; | |
my $ifs = $c->component('SNMP')->table("ifTable", columns => [qw/ifIndex ifDescr ifHCOutUcastPkts ifHCInUcastPkts/] ); | |
if ( !$ifs ) { | |
CloudForecast::Log->warn("couldnot get iftable"); | |
return [undef, undef]; | |
} | |
warn keys %interfaces; my $if = List::Util::first { | |
exists $interfaces{$_->{ifDescr}} | |
} values %{$ifs}; | |
if ( !$if ) { | |
CloudForecast::Log->warn("couldnot find network interface '$interface'"); | |
return [undef, undef]; } | |
CloudForecast::Log->debug("found network interface '$interface' with ifIndex:$if->{ifIndex}"); | |
my $in = $if->{ifHCInUcastPkts}; | |
my $out = $if->{ifHCOutUcastPkts}; | |
return [$in, $out]; | |
} | |
my @map = map { [ $_, $interface] } qw/ifHCInOctets ifHCOutOctets/ | |
if $c->component('SNMP')->config->{version} eq '2'; | |
return $c->component('SNMP')->get(@map); | |
}; | |
__DATA__ | |
@@ traffic | |
DEF:in=<%RRD%>:in:AVERAGE | |
DEF:out=<%RRD%>:out:AVERAGE | |
AREA:in#006000: Inbound | |
GPRINT:in:LAST:Current\:%6.2lf %sps | |
GPRINT:in:AVERAGE:Ave\:%6.2lf %sps | |
GPRINT:in:MAX:Max\:%6.2lf %sps\c | |
LINE1:out#000099: Outbound | |
GPRINT:out:LAST:Current\:%6.2lf %sps | |
GPRINT:out:AVERAGE:Ave\:%6.2lf %sps | |
GPRINT:out:MAX:Max\:%6.2lf %sps\c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment