| Linux-net-dev documentation | Contained in the Linux-net-dev distribution. |
Linux::net::dev - Perl extension for parsing /proc/net/dev
use Linux::net::dev;
my $devs = Linux::net::dev::info();
print "Devices (bytes read):\n";
foreach (keys %$devs) {
print " $_ ($devs->{$_}->{rbytes})\n";
}
Linux::net::dev parses /proc/net/dev for network devices statistics. The package contains these functions:
This function returns hash reference. Keys are devices' ids and values are data hash references. Data hash has resource names for keys and their respective values as associated values.
Takes device id as a single argument and returns that device's data.
Takes list of device ids as arguments and returns array with those devices' data.
Recognized resources (data hash keys): rbytes, rcompressed, rdrop, rerrs, rfifo, rframe, rmulticast, rpackets, tbytes, tcarrier, tcolls, tcompressed, tdrop, terrs, tfifo, tpackets,
Resources begining with "r" are values for read data, and those begining with "t" are values for transmited data.
Package was built and tested on RedHat 7.2, kernel 2.4.7-10 and might not work on some other versions. Please report bugs along with your kernel version (uname -r or uname -a).
/proc/net/dev
Perl 5.000
perl(1).
Vedran Sego, vsego@math.hr
| Linux-net-dev documentation | Contained in the Linux-net-dev distribution. |
package Linux::net::dev; require 5.000; use strict; use warnings; use Carp; require Exporter; use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Linux::net::dev ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '1.00'; # Preloaded methods go here. sub info { return {} unless -r "/proc/net/dev"; open(DEV, "/proc/net/dev"); my (@titles, %result); while (my $line = <DEV>) { chomp($line); if ($line =~ /^.{6}\|([^\\]+)\|([^\\]+)$/) { my ($rec, $trans) = ($1, $2); @titles = ( (map { "r$_" } split(/\s+/, $rec)), (map { "t$_" } split(/\s+/, $trans)), ); } elsif ($line =~ /^\s*([^:]+):\s*(.*)$/) { my ($id, @data) = ($1, split(/\s+/, $2)); $result{$id} = { map { $titles[$_] => $data[$_]; } (0..$#titles) }; } } close(DEV); return \%result; } sub dev { croak "Missing parameter" unless @_; return info()->{$_[0]}; } sub devs { croak "Missing parameters" unless @_; return @{info()}{@_}; } # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is stub documentation for your module. You better edit it!