peer-as improvements

* add warning when trying to use peer-as stats with NetFlow
* slightly optimize packet handling when peer-as is disabled
* default peer-as stats to disable
This commit is contained in:
Manuel Kasper 2014-09-11 14:59:24 +02:00
parent 1777ee0aad
commit ac2faaf01b
3 changed files with 36 additions and 28 deletions

View File

@ -4,6 +4,8 @@
sFlow, Netflow v9 and v10 (IPFIX) support this. Obviously your router
needs to provide the information. Just add "/<vlan>" to the ifIndex in
your knownlinks file.
* Added support for peer-AS stats/graphs (sFlow only).
* Add -n option to asstats.pl and set showpeeras=true in config.inc to enable.
## 1.5

View File

@ -47,7 +47,7 @@ my $usage = "$0 [-rpPka]\n".
"\t(-P <sFlow UDP listen port - default $sflow_server_port, use 0 to disable sFlow)\n".
"\t-k <path to known links file>\n".
"\t-a <your own AS number> - only required for sFlow\n".
"\t-n - enable peer-as statistics\n";
"\t-n enable peer-as statistics\n";
my $rrdpath = $opt{'r'};
my $knownlinksfile = $opt{'k'};
@ -75,6 +75,10 @@ if ($sflow_server_port == $server_port) {
die("Your own AS number is non numeric\n") if ($sflow_server_port > 0 && $myas !~ /^[0-9]+$/);
if (!$sflow_server_port && $peerasstats) {
die("peer-as statistics only work with sFlow\n");
}
# reap dead children
$SIG{CHLD} = \&REAPER;
@ -566,34 +570,36 @@ sub parse_sflow {
$vlanout = $sFlowSample->{'SwitchDestVlan'};
}
# srcpeeras is the one who sent me data
# dstpeeras is the first one to which you'll send the data
# so, dstpeeras is the first entry in array
# if the array is now empty (poped before), then take $dstas
my $srcpeeras = ($sFlowSample->{'GatewayAsSourcePeer'}) ? $sFlowSample->{'GatewayAsSourcePeer'} : 0;
my $dstpeeras = 0;
if ($sFlowSample->{'GatewayDestAsPaths'}) {
$dstpeeras = @{$sFlowSample->{'GatewayDestAsPaths'}->[0]->{'AsPath'}}[0];
if (!$dstpeeras) {
$dstpeeras = 0;
}
}
if($dstpeeras == 0 && $dstas != 0){
$dstpeeras = $dstas;
}
if ($srcpeeras == $myas) {
$srcpeeras = 0;
}
if ($dstpeeras== $myas) {
$dstpeeras = 0;
}
handleflow($ipaddr, $noctets, $srcas, $dstas, $snmpin, $snmpout, $ipversion, 'sflow', $vlanin, $vlanout);
if($peerasstats && ($srcpeeras != 0 || $dstpeeras != 0)){
handleflow($ipaddr, $noctets, $srcpeeras, $dstpeeras, $snmpin, $snmpout, $ipversion, 'sflow', $vlanin, $vlanout, 1);
if ($peerasstats) {
# srcpeeras is the one who sent me data
# dstpeeras is the first one to which you'll send the data
# so, dstpeeras is the first entry in array
# if the array is now empty (poped before), then take $dstas
my $srcpeeras = ($sFlowSample->{'GatewayAsSourcePeer'}) ? $sFlowSample->{'GatewayAsSourcePeer'} : 0;
my $dstpeeras = 0;
if ($sFlowSample->{'GatewayDestAsPaths'}) {
$dstpeeras = @{$sFlowSample->{'GatewayDestAsPaths'}->[0]->{'AsPath'}}[0];
if (!$dstpeeras) {
$dstpeeras = 0;
}
}
if($dstpeeras == 0 && $dstas != 0){
$dstpeeras = $dstas;
}
if ($srcpeeras == $myas) {
$srcpeeras = 0;
}
if ($dstpeeras == $myas) {
$dstpeeras = 0;
}
if ($srcpeeras != 0 || $dstpeeras != 0) {
handleflow($ipaddr, $noctets, $srcpeeras, $dstpeeras, $snmpin, $snmpout, $ipversion, 'sflow', $vlanin, $vlanout, 1);
}
}
}
}

View File

@ -7,7 +7,7 @@ $daystatsfile = "/data/as-stats/asstats_day.txt";
$rrdtool = "/usr/bin/rrdtool";
$daypeerstatsfile = "/data/as-stats/peerasstats_day.txt";
$showpeeras = true;
$showpeeras = false;
$asinfofile = "asinfo.txt";
$knownlinksfile = "/data/as-stats/conf/knownlinks";