13 |
my $dt = 3; |
my $dt = 3; |
14 |
my $acpi_every = 10; |
my $acpi_every = 10; |
15 |
|
|
16 |
|
my $disk_blk_size = 512; |
17 |
|
|
18 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
19 |
|
|
20 |
$|=1; |
$|=1; |
38 |
|
|
39 |
warn "unit( $v )\n" if ($debug); |
warn "unit( $v )\n" if ($debug); |
40 |
|
|
41 |
my @units = qw/b k m g/; |
my @units = qw/b k M G/; |
42 |
my $o = 0; |
my $o = 0; |
43 |
|
|
44 |
while ( ( $v / 1024 ) >= 1 ) { |
while ( ( $v / 1024 ) >= 1 ) { |
56 |
} |
} |
57 |
|
|
58 |
my ( $lrx, $ltx ) = ( 0, 0 ); |
my ( $lrx, $ltx ) = ( 0, 0 ); |
59 |
|
my ( $ld_r, $ld_w ) = ( 0, 0 ); |
60 |
my $bat; |
my $bat; |
61 |
|
|
62 |
my $i = 0; |
my $i = 0; |
109 |
foreach ( split(/\n/, $net) ) { |
foreach ( split(/\n/, $net) ) { |
110 |
s/^\s+//; |
s/^\s+//; |
111 |
my @n = split(/\s+/, $_, 17); |
my @n = split(/\s+/, $_, 17); |
112 |
next unless ( $n[0] =~ m!(eth\d|ath\d):! ); |
next unless ( $n[0] =~ s!(eth\d|ath\d):!! ); |
113 |
|
|
114 |
warn dump( @n ) if ($debug); |
warn dump( @n ) if ($debug); |
115 |
$rx += $n[1]; |
$rx += $n[0]; |
116 |
$tx += $n[9]; |
$tx += $n[8]; |
117 |
} |
} |
118 |
warn "rx: $rx tx: $tx\n" if ($debug); |
warn "rx: $rx tx: $tx\n" if ($debug); |
119 |
|
|
120 |
my $r = ( $rx - $lrx ) / $dt; |
my $net_rx = ( $rx - $lrx ) / $dt; |
121 |
my $t = ( $tx - $ltx ) / $dt; |
my $net_tx = ( $tx - $ltx ) / $dt; |
122 |
( $lrx, $ltx ) = ( $rx, $tx ); |
( $lrx, $ltx ) = ( $rx, $tx ); |
123 |
|
|
124 |
printf "%s | %s |%5s > %-5s| %s%s\n", $s, $load, unit( $r ), unit( $t ), $bat, $temp; |
my $disk = read_file('/proc/diskstats'); |
125 |
|
my ( $d_r, $d_w ) = ( 0,0 ); |
126 |
|
|
127 |
|
foreach ( split(/\n/, $disk) ) { |
128 |
|
s/^\s+//; |
129 |
|
my @d = split(/\s+/, $_, 17); |
130 |
|
next unless ( $d[2] =~ m/^[sh]d\w$/ ); |
131 |
|
|
132 |
|
warn dump( @d ) if ($debug); |
133 |
|
$d_r += $d[5] * $disk_blk_size; |
134 |
|
$d_w += $d[7] * $disk_blk_size; |
135 |
|
} |
136 |
|
warn "d_r: $d_r d_w: $d_w\n" if ($debug); |
137 |
|
|
138 |
|
my $d_read = ( $d_r - $ld_r ) / $dt; |
139 |
|
my $d_write = ( $d_w - $ld_w ) / $dt; |
140 |
|
( $ld_r, $ld_w ) = ( $d_r, $d_w ); |
141 |
|
|
142 |
|
printf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n", |
143 |
|
$s, |
144 |
|
$load, |
145 |
|
unit( $d_read ), unit( $d_write ), |
146 |
|
unit( $net_rx ), unit( $net_tx ), |
147 |
|
$bat, $temp, |
148 |
|
); |
149 |
|
|
150 |
sleep $dt; |
sleep $dt; |
151 |
} |
} |