Networkd Client
Network Client
You'll want to run this puppy with some sort of automation like:
watch -n10 monitor-network.pl hostname.domain.com 10
or a better choice is to use a window manager dock monitoring program like "generic mon" in xfce4. You easily get something like this --->
The frequency number at the end just needs to match the frequency at which you are polling.
Here is the perl script
#!/usr/bin/perl
use strict;
use warnings;
my $tranunit= "B"; #default unit display is in Bytes
my $recunit= "B"; #default unit display is in Bytes
my ($host, $freq);
my (@lastresult, @result);
#Get Hostname and Frequency (how often you poll the server in seconds) from command line or interactive
if ($#ARGV+1) {
$host = $ARGV[0];
$freq = $ARGV[1];
} else {
print "Please enter fully qualified hostname: ";
$host = ;
print "Please enter poll frequency (how often you are checking in seconds): ";
$freq = ;
}
chomp($host);
chomp($freq);
#Get last results from temp file and current results from server
if (-s "/tmp/network.$host") {
@lastresult = `cat /tmp/network.$host`; #yes, this should be a hash, you fix it!
}else{
@result = `nc $host 30003 |tee /tmp/network.$host`; #oneday i'll perl-ize this into an extra 20 lines of code for compatiablity
exit 0; #first run, no data yet
}
@result = `nc $host 30003 |tee /tmp/network.$host`; #oneday i'll perl-ize this into an extra 20 lines of code for compatiablity
printf "eth: In / Out\n"; #header
my $i = 0; #this is an array index used by the 2 arrays below to keep them in sync
while ($result[$i]) {
my ($dev, $rl, $tl) = split (":", $lastresult[$i], 3);
my (undef, $r, $t) = split (":", $result[$i], 3);
$dev =~ s/eth//ig;
my $rec = ($r - $rl) / $freq; #subtract last recieved from recieved and divide result by frequency of poll
my $tran = ($t - $tl) / $freq; #subtract last transmitted from transmitted and divide result by frequency of poll
#Find the best viewing scale, Bytes, Kbytes or Mbytes
if ($rec > 1024) {
$rec = $rec / 1024;
$recunit = "K";
}
if (($recunit eq "K") && ($rec > 1024)) {
$rec = $rec / 1024;
$recunit = "M";
}
if ($tran > 1024) {
$tran = $tran / 1024;
$tranunit = "K";
}
if (($tranunit eq "K") && ($tran > 1024)) {
$tran = $tran / 1024;
$tranunit = "M";
}
#format for pretty output and...output!
$rec = sprintf("%4.f", $rec);
$tran = sprintf("%4.f", $tran);
print $dev, ":";
print $rec, $recunit, " /";
print $tran, $tranunit, "\n";
$i++; #increment the dual-array index
}