Epoch:
I've whiled away a pleasant afternoon figuring out your code. The map
function requires a more perl-ish thought process than I posses. Also,
it looks to me like you're assigning to $out the tx_packets value, not
tx_bytes.
Anyway, here is my attempt at a modification of your code to work on
systems with multiple interfaces, i.e. eth0, eth1, etc.
Code:
--------------------
my $NETDEVSTATS = '/proc/net/dev';
open(PROCNETDEV, "<$NETDEVSTATS") or die "Cannot open $NETDEVSTATS!\n";
my @netstats = <PROCNETDEV>;
close(PROCNETDEV);
#Inter-| Receive | Transmit
# face |bytes packets errs drop fifo frame compressed multicast|bytes
packets errs drop fifo colls carrier compressed
# 0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15
#Print the contents of /proc/net/dev
print @netstats;
print "\n\n";
my @bytes;
foreach my $ifstats (@netstats) {
push ( @bytes, ( map( /^.*?\w+\d{1}: # like | en3: ...
\s*(\d*) # rx_bytes in - A real large value
collapses with "en3:" above => \s*, not \s+
\s+(\d*) # rx_packets in
\s+(\d*) # rx_errs
\s+(\d*) # rx_drop
\s+(\d*) # rx_fifo
\s+(\d*) # rx_frame
\s+(\d*) # rx_compressed
\s+(\d*) # rx_multicast
\s+(\d*) # tx_bytes
\s+(\d*) # tx_packets
\s+(\d*) # tx_errs
\s+(\d*) # tx_drop
\s+(\d*) # tx_fifo
\s+(\d*) # tx_frame
\s+(\d*) # tx_compressed
\s+(\d*) # tx_multicast
/x,$ifstats) )[0,8] );
}
my $throughput = 0;
$throughput += $_ for @bytes;
printf("\nTotal throughput for all interfaces: %d\n", $throughput);
--------------------
Question: Did you weigh trying to accomplish the same sort of thing by
plucking the values from:
/sys/class/net/eth0/statistics/tx_bytes
/sys/class/net/eth0/statistics/rx_bytes
..etc.?
--
gharris999
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=49028
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix