| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Ifstat; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1432
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
58
|
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
112
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use base qw( Class::Accessor::Fast Class::ErrorHandler ); |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
2109
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ |
|
9
|
|
|
|
|
|
|
ifstat |
|
10
|
|
|
|
|
|
|
options |
|
11
|
|
|
|
|
|
|
stdin |
|
12
|
|
|
|
|
|
|
stdout |
|
13
|
|
|
|
|
|
|
stderr |
|
14
|
|
|
|
|
|
|
command |
|
15
|
|
|
|
|
|
|
/); |
|
16
|
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
12837
|
use IPC::Run qw( run ); |
|
|
2
|
|
|
|
|
121973
|
|
|
|
2
|
|
|
|
|
128
|
|
|
18
|
2
|
|
|
2
|
|
22
|
use Carp qw( carp ); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
928
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %options = ( |
|
21
|
|
|
|
|
|
|
loopmon => '-l', |
|
22
|
|
|
|
|
|
|
allifs => '-a', |
|
23
|
|
|
|
|
|
|
hideidelifs => '-z', |
|
24
|
|
|
|
|
|
|
helpmsg => '-h', |
|
25
|
|
|
|
|
|
|
displayheader => '-n', |
|
26
|
|
|
|
|
|
|
ts => '-t', |
|
27
|
|
|
|
|
|
|
totalbw => '-T', |
|
28
|
|
|
|
|
|
|
ifaceidx => '-A', |
|
29
|
|
|
|
|
|
|
fixedcolwidth => '-w', |
|
30
|
|
|
|
|
|
|
wraplines => '-W', |
|
31
|
|
|
|
|
|
|
linestats => '-S', |
|
32
|
|
|
|
|
|
|
bitsstats => '-b', |
|
33
|
|
|
|
|
|
|
quietmode => '-q', |
|
34
|
|
|
|
|
|
|
verdrivers => '-v', |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
iflist => '-i iflist separated by comma', |
|
37
|
|
|
|
|
|
|
delay => '-delay delaysecs', |
|
38
|
|
|
|
|
|
|
count => '-count pktcount' |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
|
42
|
2
|
|
|
2
|
1
|
359
|
my $class = shift; |
|
43
|
2
|
|
50
|
|
|
28
|
my $self = { |
|
44
|
|
|
|
|
|
|
ifstat => shift || 'ifstat', |
|
45
|
|
|
|
|
|
|
options => [], |
|
46
|
|
|
|
|
|
|
timeout => 0, |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
9563
|
system("$self->{ifstat} -v > /dev/null 2>&1"); |
|
50
|
2
|
|
|
|
|
59
|
my $ret = $? >> 8; |
|
51
|
2
|
50
|
33
|
|
|
128
|
if ( $ret != 0 and $ret != 1 ) { |
|
52
|
2
|
|
|
|
|
2318
|
carp "Can't find ifstat command."; |
|
53
|
2
|
|
|
|
|
526
|
exit 0; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
bless $self, $class; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub execute { |
|
60
|
0
|
|
|
0
|
1
|
|
my ($opts, %h, $delay, $count) = (); |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $self = shift; |
|
63
|
0
|
|
|
|
|
|
$opts = $self->{options}; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
%h = %{$opts}; |
|
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my @ifopts = (); |
|
68
|
0
|
|
|
|
|
|
for my $key (keys(%h)) { |
|
69
|
0
|
|
|
|
|
|
my $value = $h{$key}; |
|
70
|
0
|
0
|
|
|
|
|
if($key =~ /\-delay/) { |
|
71
|
0
|
|
|
|
|
|
$delay = $value; |
|
72
|
0
|
|
|
|
|
|
next; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
0
|
|
|
|
|
if($key =~ /\-count/) { |
|
75
|
0
|
|
|
|
|
|
$count = $value; |
|
76
|
0
|
|
|
|
|
|
next; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
0
|
|
|
|
|
if(int($value) != 1) { |
|
79
|
0
|
|
|
|
|
|
push @ifopts, $key . ' ' . $value; |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
0
|
|
|
|
|
|
push @ifopts, $key; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
my $cmd = $self->{ifstat}; |
|
86
|
0
|
|
|
|
|
|
my $ifoptsline = join ' ', @ifopts; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
0
|
|
|
|
if(defined($delay) and defined($count)) { |
|
89
|
0
|
|
|
|
|
|
$ifoptsline = $ifoptsline . " " . join " ", $delay, $count; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $fullcmd = $cmd . " " . $ifoptsline ; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my @runcmd = split / /, $fullcmd; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
run \@runcmd; |
|
97
|
0
|
|
|
|
|
|
return 0; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
*exec = \&execute; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |