[pve-devel] r5666 - in pve-common/trunk/data: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 9 12:49:59 CET 2011


Author: dietmar
Date: 2011-03-09 12:49:59 +0100 (Wed, 09 Mar 2011)
New Revision: 5666

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/ProcFSTools.pm
Log:
implement helper to read /proc/net/dev


Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-03-09 11:32:53 UTC (rev 5665)
+++ pve-common/trunk/data/ChangeLog	2011-03-09 11:49:59 UTC (rev 5666)
@@ -1,5 +1,7 @@
 2011-03-09  Proxmox Support Team  <support at proxmox.com>
 
+	* PVE/ProcFSTools.pm (read_proc_net_dev): first impl.
+
 	* PVE/Tools.pm (df): implement interruptible version of 'df'
 	(workd with timeout on NFS)
 

Modified: pve-common/trunk/data/PVE/ProcFSTools.pm
===================================================================
--- pve-common/trunk/data/PVE/ProcFSTools.pm	2011-03-09 11:32:53 UTC (rev 5665)
+++ pve-common/trunk/data/PVE/ProcFSTools.pm	2011-03-09 11:49:59 UTC (rev 5666)
@@ -196,4 +196,25 @@
     return $res;
 }
 
+sub read_proc_net_dev {
+
+    my $res = {};
+
+    my $fh = IO::File->new ("/proc/net/dev", "r");
+    return $res if !$fh;
+
+    while (defined (my $line = <$fh>)) {
+	if ($line =~ m/^\s*(.*):\s*(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)\s+/) {
+	    $res->{$1} = {
+		receive => $2,
+		transmit => $3,
+	    };
+	}
+    }
+
+    close($fh);
+
+    return $res;
+}
+
 1;




More information about the pve-devel mailing list