-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcp.pl
56 lines (56 loc) · 1.25 KB
/
tcp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
sub parse_table {
my ($file)=@_;
open(TABLE,$file);
my $table={};
while(<TABLE>) {
if ($_ =~ /^(\w+): ([\d- ]+)$/) {
my @tmp=split(/ /,$2);
$i=0;
foreach (@tmp) {
$table->{$1}->{$i}->{'value'}=$_;
$i++;
}
} elsif ($_ =~ /^(\w+): ([\w ]+)$/) {
my @tmp=split(/ /,$2);
$i=0;
foreach (@tmp) {
$table->{$1}->{$i}->{'key'}=$_;
$i++;
}
}
}
close(TABLE);
my $new_table={};
for my $tn (keys %$table) {
$tv=$table->{$tn};
while(my($k,$v)=each(%$tv)) {
$new_table->{$tn}->{$v->{'key'}}=$v->{'value'};
}
}
return $new_table;
}
use Data::Dumper;
use Sys::Hostname;
$|=0;
my $interval=10;
$ENV{PATH}="";
my $last=time;
my $type="counter";
while (true) {
my $snmp=parse_table("/proc/net/snmp");
while(my($section,$values)=each(%$snmp)) {
while(my($key,$value)=each(%$values)) {
printf("PUTVAL %s/netstats/%s-%s/%s interval=%d N:%d\n",hostname,$type,$section,$key,$interval,$value);
}
}
my $netstat=parse_table("/proc/net/netstat");
while(my($section,$values)=each(%$netstat)) {
while(my($key,$value)=each(%$values)) {
printf("PUTVAL %s/netstats/%s-%s/%s interval=%d N:%d\n",hostname,$type,$section,$key,$interval,$value);
}
}
$sleep=(time+$interval)-$last;
sleep($sleep);
$last=time;
}