Commit ed21d4e2 authored by Peter Pentchev's avatar Peter Pentchev

Reflow to a tab indent.

parent 2ca230cc
......@@ -13,6 +13,7 @@ Change log for ethstats, the network traffic statistics utility
- declare a 5.010 minimum Perl version dependency
- update the Perl source style a bit:
- use strict mode and the warnings pragma
- reflow to a tab indent
1.0 (unknown)
- released into the public domain by Drew Strieb
......
......@@ -116,94 +116,94 @@ convert();
sleep $period;
while(1) {
convert();
print time()." " if $addtime;
if ($numdevs > 1) {
print acolor 'yellow';
printf "total: %7.2f Mb/s In %7.2f Mb/s Out", $tkbin, $tkbout;
printf " - %8.1f p/s In %8.1f p/s Out", $tpackin, $tpackout;
print acolor 'reset';
print "\n";
}
foreach my $dev(sort keys %kbin) {
printf " %4s: %7.2f Mb/s In %7.2f Mb/s Out", $dev, $kbin{$dev}, $kbout{$dev};
printf " - %8.1f p/s In %8.1f p/s Out", $packin{$dev}, $packout{$dev};
print "\n";
}
if (defined($count)) {
$count--;
exit(0) if $count < 1;
}
$period = $op;
sleep $period;
convert();
print time()." " if $addtime;
if ($numdevs > 1) {
print acolor 'yellow';
printf "total: %7.2f Mb/s In %7.2f Mb/s Out", $tkbin, $tkbout;
printf " - %8.1f p/s In %8.1f p/s Out", $tpackin, $tpackout;
print acolor 'reset';
print "\n";
}
foreach my $dev(sort keys %kbin) {
printf " %4s: %7.2f Mb/s In %7.2f Mb/s Out", $dev, $kbin{$dev}, $kbout{$dev};
printf " - %8.1f p/s In %8.1f p/s Out", $packin{$dev}, $packout{$dev};
print "\n";
}
if (defined($count)) {
$count--;
exit(0) if $count < 1;
}
$period = $op;
sleep $period;
}
sub convert {
open(IN, "/proc/net/dev") || die("Can't open ip_acct: $!\n");
<IN>; <IN>;
my (%bytesin, %bytesout);
while(my $l = <IN>) {
chop($l);
my ($dev, $rest) = split(/:/, $l);
$dev =~ s/\s//g;
next if defined($iface) && $dev ne $iface;
$rest =~ s/^\s+//;
my @devarr = split(/\s+/, $rest);
$bytesin{$dev} = $devarr[0]; $bytesout{$dev} = $devarr[8];
$packin{$dev} = $devarr[1]; $packout{$dev} = $devarr[9];
}
close(IN);
$numdevs = 0;
$tpackin = 0;
$tpackout = 0;
$tkbin = 0;
$tkbout = 0;
foreach my $dev(sort keys %bytesin) {
next if($dev eq "lo");
$numdevs++;
# packets in/out
my $packdiffin = ($packin{$dev} - ($opackin{$dev} // 0));
my $packdiffout = ($packout{$dev} - ($opackout{$dev} // 0));
$packdiffin += 4294967296 if($packdiffin<0);
$packdiffout += 4294967296 if($packdiffout<0);
$opackin{$dev} = $packin{$dev};
$opackout{$dev} = $packout{$dev};
$packin{$dev} = $packdiffin / $period;
$packout{$dev} = $packdiffout / $period;
# bytes in/out
my $diffin = ($bytesin{$dev} - ($obytesin{$dev} // 0));
my $diffout = ($bytesout{$dev} - ($obytesout{$dev} // 0));
$diffin += 4294967296 if($diffin<0);
$diffout += 4294967296 if($diffout<0);
$obytesin{$dev} = $bytesin{$dev};
$obytesout{$dev} = $bytesout{$dev};
$kbin{$dev} = $diffin / $period / 1000000 * 8;
$kbout{$dev} = $diffout / $period / 1000000 * 8;
# increment totals
$tpackin += $packin{$dev};
$tpackout += $packout{$dev};
$tkbin += $kbin{$dev};
$tkbout += $kbout{$dev};
}
open(IN, "/proc/net/dev") || die("Can't open ip_acct: $!\n");
<IN>; <IN>;
my (%bytesin, %bytesout);
while(my $l = <IN>) {
chop($l);
my ($dev, $rest) = split(/:/, $l);
$dev =~ s/\s//g;
next if defined($iface) && $dev ne $iface;
$rest =~ s/^\s+//;
my @devarr = split(/\s+/, $rest);
$bytesin{$dev} = $devarr[0]; $bytesout{$dev} = $devarr[8];
$packin{$dev} = $devarr[1]; $packout{$dev} = $devarr[9];
}
close(IN);
$numdevs = 0;
$tpackin = 0;
$tpackout = 0;
$tkbin = 0;
$tkbout = 0;
foreach my $dev(sort keys %bytesin) {
next if($dev eq "lo");
$numdevs++;
# packets in/out
my $packdiffin = ($packin{$dev} - ($opackin{$dev} // 0));
my $packdiffout = ($packout{$dev} - ($opackout{$dev} // 0));
$packdiffin += 4294967296 if($packdiffin<0);
$packdiffout += 4294967296 if($packdiffout<0);
$opackin{$dev} = $packin{$dev};
$opackout{$dev} = $packout{$dev};
$packin{$dev} = $packdiffin / $period;
$packout{$dev} = $packdiffout / $period;
# bytes in/out
my $diffin = ($bytesin{$dev} - ($obytesin{$dev} // 0));
my $diffout = ($bytesout{$dev} - ($obytesout{$dev} // 0));
$diffin += 4294967296 if($diffin<0);
$diffout += 4294967296 if($diffout<0);
$obytesin{$dev} = $bytesin{$dev};
$obytesout{$dev} = $bytesout{$dev};
$kbin{$dev} = $diffin / $period / 1000000 * 8;
$kbout{$dev} = $diffout / $period / 1000000 * 8;
# increment totals
$tpackin += $packin{$dev};
$tpackout += $packout{$dev};
$tkbin += $kbin{$dev};
$tkbout += $kbout{$dev};
}
}
sub tquad {
my $n = shift;
my $a = ($n & 0xff000000) >> 24;
my $b = ($n & 0x00ff0000) >> 16;
my $c = ($n & 0x0000ff00) >> 8;
my $d = $n & 0x000000ff;
return "$a.$b.$c.$d";
my $n = shift;
my $a = ($n & 0xff000000) >> 24;
my $b = ($n & 0x00ff0000) >> 16;
my $c = ($n & 0x0000ff00) >> 8;
my $d = $n & 0x000000ff;
return "$a.$b.$c.$d";
}
sub toquad {
my $h = shift;
$h =~ /(\S\S)(\S\S)(\S\S)(\S\S)/;
my ($a, $b, $c, $d) = ($1, $2, $3, $4);
return sprintf("%d.%d.%d.%d", "0x$a", "0x$b", "0x$c", "0x$d");
my $h = shift;
$h =~ /(\S\S)(\S\S)(\S\S)(\S\S)/;
my ($a, $b, $c, $d) = ($1, $2, $3, $4);
return sprintf("%d.%d.%d.%d", "0x$a", "0x$b", "0x$c", "0x$d");
}
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