![]() ![]() |
hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
package HotSaNICmod::OSdep;sub version {($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/;return "$^O.pm $VERSION";}sub sample {my %args=@_;my @values=(0,0,0,0,0,0,0,0,0,0,0,0);open FILE,"/proc/net/tcp";while (<FILE>) {(undef,undef,undef,$state)=split;if ($state =~ /[0-9A-F]+/) {if ($state =~ /^0/) {$state =~ s/^0//;if ($state eq "A") { $state=10; }elsif ($state eq "B") { $state=11; }elsif ($state !~ /[0-9]/) { $state=0; }}else { $state=0; }$values[$state]++;}}close FILE;HotSaNICmod::do_rrd("connections","U",time,@values);}1;# known states:## 01=ESTABLISHED 02=SYN_SENT 03=SYN_RECV 04=FIN_WAIT1 05=FIN_WAIT2# 06=TIME_WAIT 07=CLOSE 09=LAST_ACK 0A=LISTEN 0B=CLOSING# TODO:## this module only stats local connections.## to stat ALL (i.e. including masq'ed) connections: use /proc/net/ip_conntrack# select all lines containing "tcp" as 1st keyword# the connection state can be found in plaintext on pos. #4## ATTENTION: This stat also contains the connections to the local configured IPs!## format of ip_conntrack:## <proto> <proto#> <expire time (sec.)> <original source> <packet destination> <src port> <dst port> <expected return source> <expected return dest> <expected ret. src port> <expected ret. dst port> <use>## for more details see:# http://www.faqs.org/docs/iptables/theconntrackentries.html# <kernel source tree>/net/ipv4/netfilter/ip_conntrack.c# <kernel source tree>/include/linux/netfilter_ipv4/ip_conntrack.h