[pve-devel] r5667 - qemu-server/pve2/PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 9 13:14:57 CET 2011


Author: dietmar
Date: 2011-03-09 13:14:57 +0100 (Wed, 09 Mar 2011)
New Revision: 5667

Modified:
   qemu-server/pve2/PVE/QemuServer.pm
Log:
add network traffic


Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2011-03-09 11:49:59 UTC (rev 5666)
+++ qemu-server/pve2/PVE/QemuServer.pm	2011-03-09 12:14:57 UTC (rev 5667)
@@ -1642,6 +1642,8 @@
     my $list =  vzlist();
     my ($uptime) = PVE::ProcFSTools::read_proc_uptime();
 
+    my $netdev = PVE::ProcFSTools::read_proc_net_dev();
+
     foreach my $vmid (keys %$list) {
 	my $cfspath = cfs_config_path($vmid);
 	my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
@@ -1670,6 +1672,9 @@
 	$d->{relcpu} = 0;
 	$d->{mem} = 0;
 
+	$d->{netout} = 0;
+	$d->{netin} = 0;
+
 	$res->{$vmid} = $d;
     }
 
@@ -1677,8 +1682,6 @@
     my $cpucount = $cpuinfo->{cpus} || 1;
     my $ctime = gettimeofday;
 
-    # fixme: network traffic 
-
     foreach my $vmid (keys %$list) {
 
 	my $d = $res->{$vmid};
@@ -1705,6 +1708,12 @@
 	    $d->{mem} = int (($rss/$vsize)*$d->{maxmem});
 	}
 
+	foreach my $dev (keys %$netdev) {
+	    next if $dev !~ m/^tap\Q${vmid}\Ei/;
+	    $d->{netout} += $netdev->{$dev}->{receive};
+	    $d->{netin} += $netdev->{$dev}->{transmit};
+	}
+
 	my $old = $last_proc_pid_stat->{$pid};
 	if (!$old) {
 	    $last_proc_pid_stat->{$pid} = { 
@@ -1733,6 +1742,7 @@
 	    $d->{cpu} = $old->{cpu};
 	    $d->{relcpu} = $old->{relcpu};
 	}
+
     }
 
     return $res;




More information about the pve-devel mailing list