/usr/share/doc/trend/examples/net is in trend 1.2-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #!/usr/bin/env perl
# network usage for trend
use strict;
use warnings;
use Time::HiRes "usleep";
# be sure to flush right away!
$| = 1;
# arguments
my $oldIn = 0;
my $oldOut = 0;
my $ms = ($ARGV[0]? $ARGV[0]: 0.1) * 1000000;
my $if = ($ARGV[1]? $ARGV[1]: "eth0");
# main loop
while()
{
open FD, "/proc/net/dev" or die;
while(<FD>)
{
my ($ent, $in, $out) = /^\s*([^\s:]+):\s*(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)/;
if($ent and $ent eq $if)
{
$oldIn = $in if($oldIn == 0);
$oldOut = $out if($oldOut == 0);
print(($in - $oldIn) . " " .
($out - $oldOut) . "\n");
$oldIn = $in;
$oldOut = $out;
last;
}
}
close FD;
usleep $ms;
}
|