Re: [PATCH]: virt-manager: start network before vm creation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
attached is a very first shot at displaying disk and network I/O in
virt-manager. No nifty graphs or sparcline yet, but the numbers seem to
match to what the guest sees. Is this the right way to go?
Cheers,
 -- Guido
# HG changeset patch
# User "Guido Günther <agx@xxxxxxxxxxx>"
# Date 1222994130 -7200
# Node ID ed3d8ed89f508a98d3569cdce417d7dd4a664cf6
# Parent  0b86cdc80b2cbeb73fddccf3ea9bcbe72ef94375
[mq]: block_stats

diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/virt-manager.schemas.in
--- a/src/virt-manager.schemas.in	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/virt-manager.schemas.in	Fri Oct 03 02:35:30 2008 +0200
@@ -73,8 +73,8 @@
       <default>0</default>
 
       <locale name="C">
-        <short>Show disk usage in summary</short>
-        <long>Show the disk usage field in the domain list summary view</long>
+        <short>Show disk IO in summary</short>
+        <long>Show the disk IO field in the domain list summary view</long>
       </locale>
     </schema>
 
diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/virtManager/details.py
--- a/src/virtManager/details.py	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/virtManager/details.py	Fri Oct 03 02:35:30 2008 +0200
@@ -437,12 +437,9 @@
             dialog.present()
             return
         dialog.show_all()
-        self.window.get_widget("overview-network-traffic-text").hide()
-        self.window.get_widget("overview-network-traffic-label").hide()
         self.window.get_widget("overview-disk-usage-bar").hide()
         self.window.get_widget("overview-disk-usage-text").hide()
         self.window.get_widget("overview-disk-usage-label").hide()
-        self.network_traffic_graph.hide()
         dialog.present()
         self.engine.increment_window_counter()
         self.update_widget_states(self.vm, self.vm.status())
@@ -763,6 +760,7 @@
         memory_vector.reverse()
         self.memory_usage_graph.set_property("data_array", memory_vector)
 
+        self.window.get_widget("overview-network-traffic-text").set_text("%d KBytes/s" % self.vm.network_rx_rate())
         network_vector = self.vm.network_traffic_vector()
         network_vector.reverse()
         self.network_traffic_graph.set_property("data_array", network_vector)
diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/virtManager/domain.py
--- a/src/virtManager/domain.py	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/virtManager/domain.py	Fri Oct 03 02:35:30 2008 +0200
@@ -149,6 +149,34 @@
             self.lastStatus = status
             self.emit("status-changed", status)
 
+    def _network_io(self):
+        rx = 0
+        tx = 0
+        for netdev in self.get_network_devices():
+            io = self.vm.interfaceStats(netdev[2])
+            if io:
+                rx += io[0]
+                tx += io[4]
+        return rx, tx
+
+    def _disk_io(self):
+        rd = 0
+        wr = 0
+        for disk in self.get_disk_devices():
+            io = self.vm.blockStats(disk[3])
+            if io:
+                rd += io[1]
+                wr += io[3]
+        return rd, wr
+
+    def _get_cur_rate(self, what):
+        if len(self.record) > 1:
+            ret = float(self.record[0][what] - self.record[1][what]) / \
+                      float(self.record[0]["timestamp"] - self.record[1]["timestamp"])
+        else:
+            ret = 0.0
+        return ret
+
     def tick(self, now):
         if self.connection.get_state() != self.connection.STATE_ACTIVE:
             return
@@ -196,6 +224,9 @@
         pcentCurrMem = info[2] * 100.0 / self.connection.host_memory_size()
         pcentMaxMem = info[1] * 100.0 / self.connection.host_memory_size()
 
+        rdBytes, wrBytes = self._disk_io()
+        rxBytes, txBytes = self._network_io()
+
         newStats = { "timestamp": now,
                      "cpuTime": cpuTime,
                      "cpuTimeAbs": cpuTimeAbs,
@@ -205,6 +236,10 @@
                      "vcpuCount": info[3],
                      "maxMem": info[1],
                      "maxMemPercent": pcentMaxMem,
+                     "diskRdKB": rdBytes / 1024,
+                     "diskWrKB": wrBytes / 1024,
+                     "netRxKB": rxBytes / 1024,
+                     "netTxKB": txBytes / 1024,
                      }
 
         self.record.insert(0, newStats)
@@ -222,6 +257,11 @@
         else:
             self.record[0]["cpuTimeMovingAvg"] = (self.record[0]["cpuTimeAbs"]-startCpuTime) / nSamples
             self.record[0]["cpuTimeMovingAvgPercent"] = (self.record[0]["cpuTimeAbs"]-startCpuTime) * 100.0 / ((now-startTimestamp)*1000.0*1000.0*1000.0 * self.connection.host_active_processor_count())
+
+        self.record[0]["diskRdRate"] = self._get_cur_rate("diskRdKB")
+        self.record[0]["diskWrRate"] = self._get_cur_rate("diskWrKB")
+        self.record[0]["netRxRate"] = self._get_cur_rate("netRxKB")
+        self.record[0]["netTxRate"] = self._get_cur_rate("netTxKB")
 
         self._update_status(info[0])
         self.emit("resources-sampled")
@@ -297,17 +337,25 @@
     def cpu_time_pretty(self):
         return "%2.2f %%" % self.cpu_time_percentage()
 
-    def network_traffic(self):
-        return 1
+    def network_rx_rate(self):
+        if len(self.record) == 0:
+            return 0
+        return self.record[0]["netRxRate"]
 
-    def network_traffic_percentage(self):
-        return 1
+    def network_tx_rate(self):
+        if len(self.record) == 0:
+            return 0
+        return self.record[0]["netTxRate"]
 
-    def disk_usage(self):
-        return 1
+    def disk_read_rate(self):
+        if len(self.record) == 0:
+            return 0
+        return self.record[0]["diskRdRate"]
 
-    def disk_usage_percentage(self):
-        return 1
+    def disk_write_rate(self):
+        if len(self.record) == 0:
+            return 0
+        return self.record[0]["diskWrRate"]
 
     def vcpu_count(self):
         if len(self.record) == 0:
diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/virtManager/manager.py
--- a/src/virtManager/manager.py	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/virtManager/manager.py	Fri Oct 03 02:35:30 2008 +0200
@@ -52,6 +52,10 @@
 ROW_MEM_USAGE = 8
 ROW_KEY = 9
 ROW_HINT = 10
+ROW_DISK_RD = 11
+ROW_DISK_WR = 12
+ROW_NET_RX = 13
+ROW_NET_TX = 14
 
 # Columns in the tree view
 COL_NAME = 0
@@ -131,8 +135,6 @@
         self.window.get_widget("menu_view_memory_usage").set_active(self.config.is_vmlist_memory_usage_visible())
         self.window.get_widget("menu_view_disk_usage").set_active(self.config.is_vmlist_disk_usage_visible())
         self.window.get_widget("menu_view_network_traffic").set_active(self.config.is_vmlist_network_traffic_visible())
-        self.window.get_widget("menu_view_disk_usage").set_sensitive(False)
-        self.window.get_widget("menu_view_network_traffic").set_sensitive(False)
 
         self.window.get_widget("vm-view").set_active(0)
 
@@ -450,6 +452,10 @@
         row.insert(ROW_MEM, vm.get_memory_pretty())
         row.insert(ROW_MEM_USAGE, vm.current_memory_percentage())
         row.insert(ROW_KEY, vm.get_uuid())
+        row.insert(ROW_DISK_RD, vm.disk_read_rate())
+        row.insert(ROW_DISK_WR, vm.disk_write_rate())
+        row.insert(ROW_NET_RX, vm.network_rx_rate())
+        row.insert(ROW_NET_TX, vm.network_tx_rate())
         row.insert(ROW_HINT, None)
 
         iter = model.append(parent, row)
@@ -471,6 +477,11 @@
         row.insert(ROW_MEM_USAGE, conn.current_memory_percentage())
         row.insert(ROW_KEY, conn.get_uri())
         row.insert(ROW_HINT, conn.get_uri())
+	# FIXME: add these:
+        row.insert(ROW_DISK_RD, 0)
+        row.insert(ROW_DISK_WR, 0)
+        row.insert(ROW_NET_RX, 0)
+        row.insert(ROW_NET_TX, 0)
 
         iter = model.append(None, row)
         path = model.get_path(iter)
@@ -524,7 +535,7 @@
             return
 
         row = self.rows[vm.get_uuid()]
-        # Handle, name, ID, status, status icon, cpu, cpu graph, vcpus, mem, mem bar
+        # Handle, name, ID, status, status icon, cpu, cpu graph, vcpus, mem, mem bar, diskRead, diskWrite, netRx, netTx
         if vm.get_id() == -1:
             row[ROW_ID] = "-"
         else:
@@ -535,6 +546,10 @@
         row[ROW_VCPUS] = vm.vcpu_count()
         row[ROW_MEM] = vm.get_memory_pretty()
         row[ROW_MEM_USAGE] = vm.current_memory_percentage()
+        row[ROW_DISK_RD] = vm.disk_read_rate()
+        row[ROW_DISK_WR] = vm.disk_write_rate()
+        row[ROW_NET_RX] = vm.network_rx_rate()
+        row[ROW_NET_TX] = vm.network_tx_rate()
         model.row_changed(row.path, row.iter)
 
         if vm == self.current_vm():
@@ -787,8 +802,8 @@
     def prepare_vmlist(self):
         vmlist = self.window.get_widget("vm-list")
 
-        # Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar, uuid
-        model = gtk.TreeStore(object, str, str, str, gtk.gdk.Pixbuf, str, int, str, int, str, str)
+        # Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar, uuid, diskRead, diskWrite, netRx, netTx
+        model = gtk.TreeStore(object, str, str, str, gtk.gdk.Pixbuf, str, int, str, int, str, str, int, int, int, int)
         vmlist.set_model(model)
         try:
             vmlist.set_tooltip_column(ROW_HINT)
@@ -803,8 +818,8 @@
         cpuUsageCol = gtk.TreeViewColumn(_("CPU usage"))
         virtualCPUsCol = gtk.TreeViewColumn(_("VCPUs"))
         memoryUsageCol = gtk.TreeViewColumn(_("Memory usage"))
-        diskUsageCol = gtk.TreeViewColumn(_("Disk usage"))
-        networkTrafficCol = gtk.TreeViewColumn(_("Network traffic"))
+        diskUsageCol = gtk.TreeViewColumn(_("Disk IO (Read/Write)"))
+        networkTrafficCol = gtk.TreeViewColumn(_("Network IO (RX/TX)"))
 
         vmlist.append_column(nameCol)
         vmlist.append_column(idCol)
@@ -826,12 +841,12 @@
 
         name_txt = gtk.CellRendererText()
         nameCol.pack_start(name_txt, True)
-        nameCol.add_attribute(name_txt, 'text', 1)
+        nameCol.add_attribute(name_txt, 'text', ROW_NAME)
         nameCol.set_sort_column_id(VMLIST_SORT_NAME)
 
         id_txt = gtk.CellRendererText()
         idCol.pack_start(id_txt, True)
-        idCol.add_attribute(id_txt, 'text', 2)
+        idCol.add_attribute(id_txt, 'text', ROW_ID)
         idCol.set_visible(self.config.is_vmlist_domain_id_visible())
         idCol.set_sort_column_id(VMLIST_SORT_ID)
 
@@ -839,44 +854,48 @@
         status_icon = gtk.CellRendererPixbuf()
         statusCol.pack_start(status_icon, False)
         statusCol.pack_start(status_txt, False)
-        statusCol.add_attribute(status_txt, 'text', 3)
-        statusCol.add_attribute(status_icon, 'pixbuf', 4)
+        statusCol.add_attribute(status_txt, 'text', ROW_STATUS)
+        statusCol.add_attribute(status_icon, 'pixbuf', ROW_STATUS_ICON)
         statusCol.set_visible(self.config.is_vmlist_status_visible())
 
         cpuUsage_txt = gtk.CellRendererText()
         cpuUsage_img = sparkline.CellRendererSparkline()
         cpuUsageCol.pack_start(cpuUsage_txt, False)
         cpuUsageCol.pack_start(cpuUsage_img, False)
-        cpuUsageCol.add_attribute(cpuUsage_txt, 'text', 5)
+        cpuUsageCol.add_attribute(cpuUsage_txt, 'text', ROW_CPU)
         cpuUsageCol.set_cell_data_func(cpuUsage_img, self.cpu_usage_img, None)
         cpuUsageCol.set_visible(self.config.is_vmlist_cpu_usage_visible())
         cpuUsageCol.set_sort_column_id(VMLIST_SORT_CPU_USAGE)
 
         virtualCPUs_txt = gtk.CellRendererText()
         virtualCPUsCol.pack_start(virtualCPUs_txt, False)
-        virtualCPUsCol.add_attribute(virtualCPUs_txt, 'text', 6)
+        virtualCPUsCol.add_attribute(virtualCPUs_txt, 'text', ROW_VCPUS)
         virtualCPUsCol.set_visible(self.config.is_vmlist_virtual_cpus_visible())
 
         memoryUsage_txt = gtk.CellRendererText()
         memoryUsage_img = gtk.CellRendererProgress()
         memoryUsageCol.pack_start(memoryUsage_txt, False)
         memoryUsageCol.pack_start(memoryUsage_img, False)
-        memoryUsageCol.add_attribute(memoryUsage_txt, 'text', 7)
-        memoryUsageCol.add_attribute(memoryUsage_img, 'value', 8)
+        memoryUsageCol.add_attribute(memoryUsage_txt, 'text', ROW_MEM)
+        memoryUsageCol.add_attribute(memoryUsage_img, 'value', ROW_MEM_USAGE)
         memoryUsageCol.set_visible(self.config.is_vmlist_memory_usage_visible())
         memoryUsageCol.set_sort_column_id(VMLIST_SORT_MEMORY_USAGE)
 
-        diskUsage_txt = gtk.CellRendererText()
-        diskUsage_img = gtk.CellRendererProgress()
-        diskUsageCol.pack_start(diskUsage_txt, False)
-        diskUsageCol.pack_start(diskUsage_img, False)
+        diskUsageIn_txt = gtk.CellRendererText()
+        diskUsageOut_txt = gtk.CellRendererText()
+        diskUsageCol.pack_start(diskUsageIn_txt, False)
+        diskUsageCol.pack_start(diskUsageOut_txt, False)
+        diskUsageCol.add_attribute(diskUsageIn_txt, 'text', ROW_DISK_RD)
+        diskUsageCol.add_attribute(diskUsageOut_txt, 'text', ROW_DISK_WR)
         diskUsageCol.set_visible(self.config.is_vmlist_disk_usage_visible())
         diskUsageCol.set_sort_column_id(VMLIST_SORT_DISK_USAGE)
 
-        networkTraffic_txt = gtk.CellRendererText()
-        networkTraffic_img = gtk.CellRendererProgress()
-        networkTrafficCol.pack_start(networkTraffic_txt, False)
-        networkTrafficCol.pack_start(networkTraffic_img, False)
+        networkTrafficIn_txt = gtk.CellRendererText()
+        networkTrafficOut_txt = gtk.CellRendererText()
+        networkTrafficCol.pack_start(networkTrafficIn_txt, False)
+        networkTrafficCol.pack_start(networkTrafficOut_txt, False)
+        networkTrafficCol.add_attribute(networkTrafficIn_txt, 'text', ROW_NET_RX)
+        networkTrafficCol.add_attribute(networkTrafficOut_txt, 'text', ROW_NET_TX)
         networkTrafficCol.set_visible(self.config.is_vmlist_network_traffic_visible())
         networkTrafficCol.set_sort_column_id(VMLIST_SORT_NETWORK_USAGE)
 
diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/vmm-details.glade
--- a/src/vmm-details.glade	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/vmm-details.glade	Fri Oct 03 02:35:30 2008 +0200
@@ -1323,7 +1323,7 @@
 				  <child>
 				    <widget class="GtkLabel" id="overview-disk-usage-label">
 				      <property name="visible">True</property>
-				      <property name="label" translatable="yes">Disk usage:</property>
+				      <property name="label" translatable="yes">Disk IO:</property>
 				      <property name="use_underline">False</property>
 				      <property name="use_markup">False</property>
 				      <property name="justify">GTK_JUSTIFY_LEFT</property>
diff -r 0b86cdc80b2c -r ed3d8ed89f50 src/vmm-manager.glade
--- a/src/vmm-manager.glade	Thu Oct 02 19:43:42 2008 +0200
+++ b/src/vmm-manager.glade	Fri Oct 03 02:35:30 2008 +0200
@@ -262,7 +262,7 @@
 		  <child>
 		    <widget class="GtkCheckMenuItem" id="menu_view_disk_usage">
 		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">Disk usage</property>
+		      <property name="label" translatable="yes">Disk IO</property>
 		      <property name="use_underline">True</property>
 		      <property name="active">True</property>
 		      <signal name="activate" handler="on_menu_view_disk_usage_activate" last_modification_time="Tue, 28 Mar 2006 16:35:00 GMT"/>
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux