use 'ss' if available in Linux instead of 'netstat'

This commit is contained in:
Alexander Lebedev 2018-01-21 20:53:47 +03:00
parent 89ed14b174
commit 5e4bbc494e
1 changed files with 104 additions and 53 deletions

View File

@ -179,6 +179,56 @@ sub netstat_update {
my $rrdata = "N";
if($config->{os} eq "Linux") {
if (`which ss`) {
if(open(IN, "ss -Hna -f inet |")) {
while(<IN>) {
m/^(\S+)\s+(\S+)/;
my $proto = $1 || '';
my $state = $2 || '';
if ($proto eq 'tcp') {
if ($state eq "LISTEN") { $i4_listen++ }
elsif ($state eq "ESTAB") { $i4_estblshd++ }
elsif ($state eq "TIME-WAIT") { $i4_timewait++ }
elsif ($state eq "CLOSE-WAIT") { $i4_closewait++ }
elsif ($state eq "FIN-WAIT1") { $i4_finwait1++ }
elsif ($state eq "FIN-WAIT2") { $i4_finwait2++ }
elsif ($state eq "SYN-SENT") { $i4_synsent++ }
elsif ($state eq "SYN-RECV") { $i4_synrecv++ }
elsif ($state eq "CLOSING") { $i4_closing++ }
elsif ($state eq "LAST-ACK") { $i4_lastack++ }
elsif ($state eq "UNCONN") { $i4_closed++ }
elsif ($state eq "UNKNOWN") { $i4_unknown++ }
} elsif ($proto eq 'udp') {
$i4_udp++;
}
}
close(IN);
}
if(open(IN, "ss -Hna -f inet6 |")) {
while(<IN>) {
m/^(\S+)\s+(\S+)/;
my $proto = $1 || '';
my $state = $2 || '';
if ($proto eq 'tcp') {
if ($state eq "LISTEN") { $i6_listen++ }
elsif ($state eq "ESTAB") { $i6_estblshd++ }
elsif ($state eq "TIME-WAIT") { $i6_timewait++ }
elsif ($state eq "CLOSE-WAIT") { $i6_closewait++ }
elsif ($state eq "FIN-WAIT1") { $i6_finwait1++ }
elsif ($state eq "FIN-WAIT2") { $i6_finwait2++ }
elsif ($state eq "SYN-SENT") { $i6_synsent++ }
elsif ($state eq "SYN-RECV") { $i6_synrecv++ }
elsif ($state eq "CLOSING") { $i6_closing++ }
elsif ($state eq "LAST-ACK") { $i6_lastack++ }
elsif ($state eq "UNCONN") { $i6_closed++ }
elsif ($state eq "UNKNOWN") { $i6_unknown++ }
} elsif ($proto eq 'udp') {
$i6_udp++;
}
}
close(IN);
}
} else {
if(open(IN, "netstat -tn -A inet |")) {
while(<IN>) {
my $last = (split(' ', $_))[-1];
@ -239,6 +289,7 @@ sub netstat_update {
}
close(IN);
}
}
} elsif(grep {$_ eq $config->{os}} ("FreeBSD", "OpenBSD")) {
if(open(IN, "netstat -na -p tcp -f inet |")) {
while(<IN>) {