package HotSaNICmod::OSdep; use RRDs; sub version { ($VERSION = '$Revision: 1.3 $') =~ 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,"/usr/bin/netstat -a -n -p tcp |" or die time."netstat: $!"; # skip 2 line ; ; my $state; foreach () { (undef,undef,undef,undef,undef,$state)=split; if ($state eq "ESTABLISHED") { $values[1]++; } elsif($state eq "SYN_SENT") { $values[2]++; } elsif($state eq "SYN_RECV") { $values[3]++; } elsif($state eq "FIN_WAIT_1") { $values[4]++; } elsif($state eq "FIN_WAIT_2") { $values[5]++; } elsif($state eq "TIME_WAIT") { $values[6]++; } elsif($state eq "CLOSE") { $values[7]++; } elsif($state eq "LAST_ACK") { $values[9]++; } elsif($state eq "LISTEN") { $values[10]++; } elsif($state eq "CLOSING") { $values[11]++; } else { $values[0]++; } } close FILE; store_values($args{MODNAME},@values); } sub store_values { my ($MODNAME,@val)=@_; if ( ! -e "rrd/connections.rrd" ) { system("./makerrd","connections","U") } RRDs::update "rrd/connections.rrd",time.":".join(":",@val); if ($ERROR = RRDs::error) { print time," ","$MODNAME: unable to update `connections.rrd': $ERROR\n"; } } 1;