line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::linux::pps Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Linux::Pps; |
7
|
1
|
|
|
1
|
|
846
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Network::Device Metabrik::File::Text); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
548
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes_default => { |
19
|
|
|
|
|
|
|
strip_crlf => 1, |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
commands => { |
22
|
|
|
|
|
|
|
loop => [ qw(device|OPTIONAL interval|OPTIONAL) ], |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub loop { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my ($device, $interval) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
0
|
|
|
|
$device ||= $self->default or return; |
32
|
0
|
|
0
|
|
|
|
$interval ||= 1; # 1 second interval |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if (ref($device) eq 'ARRAY') { |
35
|
0
|
|
|
|
|
|
$device = $device->[0]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $rx_packets = "/sys/class/net/$device/statistics/rx_packets"; |
39
|
0
|
|
|
|
|
|
my $tx_packets = "/sys/class/net/$device/statistics/tx_packets"; |
40
|
0
|
0
|
0
|
|
|
|
if (! -f $rx_packets && ! -f $tx_packets) { |
41
|
0
|
|
|
|
|
|
return $self->log->error("loop: file not found [$rx_packets] and [$tx_packets]"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
while (1) { |
45
|
0
|
0
|
|
|
|
|
my $r1 = $self->read($rx_packets) or return; |
46
|
0
|
0
|
|
|
|
|
my $t1 = $self->read($tx_packets) or return; |
47
|
0
|
|
|
|
|
|
sleep($interval); |
48
|
0
|
0
|
|
|
|
|
my $r2 = $self->read($rx_packets) or return; |
49
|
0
|
0
|
|
|
|
|
my $t2 = $self->read($tx_packets) or return; |
50
|
0
|
|
|
|
|
|
my $rdiff = $r2->[0] - $r1->[0]; |
51
|
0
|
|
|
|
|
|
my $tdiff = $t2->[0] - $t1->[0]; |
52
|
0
|
|
|
|
|
|
$self->log->info("loop: TX [$device]: $tdiff pkts/s RX [$device]: $rdiff pkts/s"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |