* add support for setting the sampling rate per link in the knownlinks file

This commit is contained in:
Manuel Kasper 2013-03-17 15:12:40 +00:00
parent 0ba0fbd811
commit 1c78eedb01
4 changed files with 38 additions and 5 deletions

3
README
View File

@ -7,6 +7,9 @@ Changes
-------
v1.xx Generate v6 RRD DS in contrib/sync_ds.pl too
(spotted by Peter Hansen)
Add support for setting the sampling rate per link in the
knownlinks file.
v1.40 Add support for NetFlow v9 to netflow-asstatd.pl
(sponsored by Xplornet Communications Inc.)

View File

@ -11,6 +11,7 @@ use RRDs;
use Getopt::Std;
my %knownlinks;
my %link_samplingrates;
my $samplingrate = 1; # rate for sampled NetFlow (or = 1 for unsampled)
@ -351,9 +352,17 @@ sub flush_cache {
while (my ($dsname, $value) = each(%$cacheent)) {
next if ($dsname !~ /_(in|out)$/);
my $tag = $dsname;
$tag =~ s/(_v6)?_(in|out)$//;
my $cursamplingrate = $samplingrate;
if ($link_samplingrates{$tag}) {
$cursamplingrate = $link_samplingrates{$tag};
}
push(@templatearg, $dsname);
push(@args, $value * $samplingrate);
push(@args, $value * $cursamplingrate);
}
RRDs::update($rrdfile, "--template", join(':', @templatearg),
@ -416,16 +425,22 @@ sub getrrdfile {
sub read_knownlinks {
my %knownlinks_tmp;
my %link_samplingrates_tmp;
open(KLFILE, $knownlinksfile) or die("Cannot open $knownlinksfile!");
while (<KLFILE>) {
chomp;
next if (/(^\s*#)|(^\s*$)/); # empty line or comment
my ($routerip,$ifindex,$tag,$descr,$color) = split(/\t+/);
my ($routerip,$ifindex,$tag,$descr,$color,$samplingrate) = split(/\t+/);
$knownlinks_tmp{"${routerip}_${ifindex}"} = $tag;
if ($samplingrate) {
$link_samplingrates_tmp{$tag} = $samplingrate;
}
}
close(KLFILE);
%knownlinks = %knownlinks_tmp;
%link_samplingrates = %link_samplingrates_tmp;
return;
}

View File

@ -11,6 +11,7 @@ use RRDs;
use Getopt::Std;
my %knownlinks;
my %link_samplingrates;
my $samplingrate = 512;
@ -253,9 +254,17 @@ sub flush_cache {
while (my ($dsname, $value) = each(%$cacheent)) {
next if ($dsname !~ /_(in|out)$/);
my $tag = $dsname;
$tag =~ s/(_v6)?_(in|out)$//;
my $cursamplingrate = $samplingrate;
if ($link_samplingrates{$tag}) {
$cursamplingrate = $link_samplingrates{$tag};
}
push(@templatearg, $dsname);
push(@args, $value * $samplingrate);
push(@args, $value * $cursamplingrate);
}
RRDs::update($rrdfile, "--template", join(':', @templatearg),
@ -316,16 +325,22 @@ sub getrrdfile {
sub read_knownlinks {
my %knownlinks_tmp;
my %link_samplingrates_tmp;
open(KLFILE, $knownlinksfile) or die("Cannot open $knownlinksfile!");
while (<KLFILE>) {
chomp;
next if (/(^\s*#)|(^\s*$)/); # empty line or comment
my ($routerip,$ifindex,$tag,$descr,$color) = split(/\t+/);
my ($routerip,$ifindex,$tag,$descr,$color,$samplingrate) = split(/\t+/);
$knownlinks_tmp{"${routerip}_${ifindex}"} = $tag;
if ($samplingrate) {
$link_samplingrates_tmp{$tag} = $samplingrate;
}
}
close(KLFILE);
%knownlinks = %knownlinks_tmp;
%link_samplingrates = %link_samplingrates_tmp;
return;
}

View File

@ -1,4 +1,4 @@
# Router IP SNMP ifindex tag description color
# Router IP SNMP ifindex tag description color samplingrate (optional)
# note: tabs must be used to separate fields (not spaces)
192.0.2.1 15 uplink1 Uplink 1 D41C0E
192.0.2.1 23 uplink2 Uplink 2 E45605