mirror of https://github.com/aredn/aredn.git
feature: enhance snrlog to handle neigbors dropping in and out and leaving mesh
This commit is contained in:
parent
b2c4913680
commit
ad856844bf
|
@ -35,8 +35,20 @@
|
||||||
|
|
||||||
$MAXLINES=2880; # 2 days worth
|
$MAXLINES=2880; # 2 days worth
|
||||||
$tmpdir="/tmp/snrlog";
|
$tmpdir="/tmp/snrlog";
|
||||||
|
$lastdat="/tmp/snr.dat";
|
||||||
$sigdir="/sys/kernel/debug/ieee80211/phy0/netdev\:wlan0/stations";
|
$sigdir="/sys/kernel/debug/ieee80211/phy0/netdev\:wlan0/stations";
|
||||||
|
|
||||||
|
if ( -e $lastdat )
|
||||||
|
{
|
||||||
|
open(FILE, "<$lastdat") or die "Unable to read \"$lastdat\"";
|
||||||
|
while($line = <FILE>)
|
||||||
|
{
|
||||||
|
($mac,$last) = split /\|/, $line;
|
||||||
|
chomp ($lasttime{$mac} = $last);
|
||||||
|
}
|
||||||
|
close FILE ;
|
||||||
|
}
|
||||||
|
|
||||||
$nf = `iw wlan0 survey dump | grep -A 1 'in use' | tail -1`;
|
$nf = `iw wlan0 survey dump | grep -A 1 'in use' | tail -1`;
|
||||||
$nf =~ s/^[^-\d]*([-\d]+).*$/$1/;
|
$nf =~ s/^[^-\d]*([-\d]+).*$/$1/;
|
||||||
chomp $nf;
|
chomp $nf;
|
||||||
|
@ -45,20 +57,25 @@ if (! -e $tmpdir ) { system("mkdir $tmpdir > /dev/null"); }
|
||||||
|
|
||||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
||||||
$d = sprintf ("%02d/%02d %02d:%02d:%02d",$mon+1, $mday,$hour, $min, $sec);
|
$d = sprintf ("%02d/%02d %02d:%02d:%02d",$mon+1, $mday,$hour, $min, $sec);
|
||||||
|
chomp ($now=`cat /proc/uptime | cut -f1 -d" "`);
|
||||||
|
|
||||||
foreach $sigmac ( `ls $sigdir` )
|
foreach $sigmac ( `ls $sigdir` )
|
||||||
{
|
{
|
||||||
chomp $sigmac;
|
chomp $sigmac;
|
||||||
$filename = `ls $tmpdir/$sigmac*` ;
|
$isFile = "";
|
||||||
$filename =~ /^.*\/([^-]*)-(.*)$/;
|
$hnamef = "";
|
||||||
|
$ipsig = "";
|
||||||
|
$macfname = "";
|
||||||
|
$macfname = `ls $tmpdir/$sigmac*` ;
|
||||||
|
$macfname =~ /^.*\/([^-]*)-(.*)$/;
|
||||||
$isFile = $1;
|
$isFile = $1;
|
||||||
$hnamef = $2;
|
$hnamef = $2;
|
||||||
|
|
||||||
chomp ($ip = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`);
|
chomp ($ipsig = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`);
|
||||||
$hname="";
|
$hname="";
|
||||||
foreach(`nslookup $ip`)
|
foreach(`nslookup $ipsig`)
|
||||||
{
|
{
|
||||||
next unless ($hname) = /Address 1: $ip (\S+)/;
|
next unless ($hname) = /Address 1: $ipsig (\S+)/;
|
||||||
$hname =~ s/\..*$// ;
|
$hname =~ s/\..*$// ;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -67,9 +84,9 @@ foreach $sigmac ( `ls $sigdir` )
|
||||||
{
|
{
|
||||||
$sigdat = "$sigmac-$hname";
|
$sigdat = "$sigmac-$hname";
|
||||||
}
|
}
|
||||||
elsif ( $hnamef eq $ip and $hname )
|
elsif ( $hnamef eq $ipsig and $hname )
|
||||||
{
|
{
|
||||||
system("mv $tmpdir/$sigmac-$ip $tmpdir/$sigmac-$hname > /dev/null");
|
system("mv $tmpdir/$sigmac-$ipsig $tmpdir/$sigmac-$hname > /dev/null");
|
||||||
$sigdat = "$sigmac-$hname";
|
$sigdat = "$sigmac-$hname";
|
||||||
}
|
}
|
||||||
elsif ($hname and ! $hnamef and $isFile )
|
elsif ($hname and ! $hnamef and $isFile )
|
||||||
|
@ -77,14 +94,14 @@ foreach $sigmac ( `ls $sigdir` )
|
||||||
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$hname > /dev/null");
|
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$hname > /dev/null");
|
||||||
$sigdat = "$sigmac-$hname";
|
$sigdat = "$sigmac-$hname";
|
||||||
}
|
}
|
||||||
elsif (( $hnamef eq $ip) or ( $ip and ! $isFile ))
|
elsif (( $hnamef eq $ipsig) or ( $ipsig and ! $isFile ))
|
||||||
{
|
{
|
||||||
$sigdat = "$sigmac-$ip";
|
$sigdat = "$sigmac-$ipsig";
|
||||||
}
|
}
|
||||||
elsif ( $isFile and ! $hnamef and $ip )
|
elsif ( $isFile and ! $hnamef and $ipsig )
|
||||||
{
|
{
|
||||||
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ip > /dev/null");
|
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ipsig > /dev/null");
|
||||||
$sigdat = "$sigmac-$ip";
|
$sigdat = "$sigmac-$ipsig";
|
||||||
}
|
}
|
||||||
elsif ($hnamef and ! $hname )
|
elsif ($hnamef and ! $hname )
|
||||||
{
|
{
|
||||||
|
@ -101,7 +118,7 @@ foreach $sigmac ( `ls $sigdir` )
|
||||||
}
|
}
|
||||||
|
|
||||||
chomp ($siglevel = `cat $sigdir/$sigmac/last_signal`) ;
|
chomp ($siglevel = `cat $sigdir/$sigmac/last_signal`) ;
|
||||||
if ($siglevel < -100 or $siglevel >= 0 ) { next; }
|
if ($siglevel < -95 or $siglevel >= 0 ) { $siglevel = "-95"; }
|
||||||
|
|
||||||
open(my $fh, '>>', "$tmpdir/$sigdat") or die "Could not open file '$tmpdir/$sigdat' $!";
|
open(my $fh, '>>', "$tmpdir/$sigdat") or die "Could not open file '$tmpdir/$sigdat' $!";
|
||||||
print $fh "$d,$siglevel,$nf\n";
|
print $fh "$d,$siglevel,$nf\n";
|
||||||
|
@ -114,4 +131,30 @@ foreach $sigmac ( `ls $sigdir` )
|
||||||
$rc=`tail -n$MAXLINES $tmpdir/$sigdat > $tmpdir/$sigdat.tmp`;
|
$rc=`tail -n$MAXLINES $tmpdir/$sigdat > $tmpdir/$sigdat.tmp`;
|
||||||
$rc=`mv $tmpdir/$sigdat.tmp $tmpdir/$sigdat`;
|
$rc=`mv $tmpdir/$sigdat.tmp $tmpdir/$sigdat`;
|
||||||
}
|
}
|
||||||
|
$neighbor{$sigmac}="1";
|
||||||
|
$lasttime{$sigmac}=$now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# process neigbors that are no longer connected
|
||||||
|
foreach $sigmac (`ls $tmpdir`)
|
||||||
|
{
|
||||||
|
chomp $sigmac ;
|
||||||
|
$sigf = $sigmac;
|
||||||
|
$sigmac =~ s/-.*$//;
|
||||||
|
|
||||||
|
if ( $now - $lasttime{$sigmac} > 25000 )
|
||||||
|
{
|
||||||
|
unlink "$tmpdir/$sigf" ;
|
||||||
|
delete $lasttime{$sigmac};
|
||||||
|
}
|
||||||
|
elsif ( ! $neighbor{$sigmac} )
|
||||||
|
{
|
||||||
|
open(my $fh, '>>', "$tmpdir/$sigf") or die "Could not open file '$tmpdir/$sigf' $!";
|
||||||
|
print $fh "$d,-95,-95\n";
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open($fh, ">$lastdat") or die "Unable to create \"$lastdat\" $!";
|
||||||
|
for (keys %lasttime) { print $fh "$_|$lasttime{$_}\n"; }
|
||||||
|
close $fh;
|
||||||
|
|
Loading…
Reference in New Issue