Commit 5db5670c authored by Peter Pentchev's avatar Peter Pentchev

Pass the period as an argument, get rid of $op.

parent 5b81c6ca
Pipeline #481269 skipped
......@@ -26,7 +26,6 @@ BEGIN {
};
}
my $period = 10;
my ($COLOR, $addtime, $count, $iface);
my %prevstat;
my %total = (kb => {}, packets => {});
......@@ -84,9 +83,9 @@ sub reset_totals()
%total = (kb => {}, packets => {});
}
sub update_traffic($ $)
sub update_traffic($ $ $)
{
my ($dev, $odev) = @_;
my ($dev, $odev, $period) = @_;
for my $what (keys %{$dev}) {
for my $dir (keys %{$dev->{$what}}) {
......@@ -119,8 +118,10 @@ sub add_up_totals($ $)
# eth0: 1217210 9400 0 0 0 8 0 11 1207648 8019 0 0 0 0 0 0
# eth1: 2039952 21982 6 0 0 6 0 0 47000710 34813 0 0 0 821 0 0
sub convert()
sub convert($)
{
my ($period) = @_;
open my $in, '/proc/net/dev' or die "Can't open /proc/net/dev: $!\n";
<$in>; <$in>;
my %devs;
......@@ -151,7 +152,7 @@ sub convert()
delete $devs{lo};
foreach my $dev (sort { $a->{name} cmp $b->{name} } values %devs) {
$prevstat{$dev->{name}} //= { name => $dev->{name} };
update_traffic $dev->{data}, $prevstat{$dev->{name}};
update_traffic $dev->{data}, $prevstat{$dev->{name}}, $period;
$dev->{data}->{kb} = {
in => $dev->{data}->{bytes}->{in} / 1000000 * 8,
out => $dev->{data}->{bytes}->{out} / 1000000 * 8,
......@@ -166,6 +167,7 @@ MAIN:
{
$| = 1;
my $period = 10;
my %opts;
getopts 'Cc:hi:Mn:tV', \%opts or usage(1);
......@@ -203,13 +205,11 @@ MAIN:
$COLOR = $have_ansi_color && -t \*STDOUT;
}
my $op = $period;
$period = 1;
convert;
sleep $period;
convert 1;
sleep 1;
while(1) {
my $devs = convert;
my $devs = convert $period;
print time.' ' if $addtime;
if (scalar keys %{$devs} > 1) {
say acolor('yellow').
......@@ -223,7 +223,6 @@ MAIN:
$count--;
exit 0 if $count < 1;
}
$period = $op;
sleep $period;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment