allow to disable sampling
triggered via the vmlist-fields/{network_traffic,disk_io} gconf keys. We do this by replacing the sampling routines with noops. Also adjust the label in the vm details to say "sampling disabled".
This commit is contained in:
parent
b19924f06f
commit
088f56d543
|
@ -814,20 +814,24 @@ class vmmDetails(gobject.GObject):
|
|||
self.window.get_widget("overview-memory-usage-text").set_text("%d MB of %d MB" % \
|
||||
(int(round(vm_memory/1024.0)), \
|
||||
int(round(host_memory/1024.0))))
|
||||
self.window.get_widget("overview-network-traffic-text").set_markup(_rx_tx_text(
|
||||
self.vm.network_rx_rate(),
|
||||
self.vm.network_tx_rate(),
|
||||
"KBytes/s"))
|
||||
self.window.get_widget("overview-disk-usage-text").set_markup(_rx_tx_text(
|
||||
self.vm.disk_read_rate(),
|
||||
self.vm.disk_write_rate(),
|
||||
"KBytes/s"))
|
||||
|
||||
history_len = self.config.get_stats_history_length()
|
||||
self.cpu_usage_graph.set_property("data_array", self.vm.cpu_time_vector())
|
||||
self.memory_usage_graph.set_property("data_array", self.vm.current_memory_vector())
|
||||
self.network_traffic_graph.set_property("data_array", self.vm.network_traffic_vector())
|
||||
self.disk_io_graph.set_property("data_array", self.vm.disk_io_vector())
|
||||
|
||||
if self.config.is_vmlist_network_traffic_visible():
|
||||
text = _rx_tx_text(self.vm.network_rx_rate(), self.vm.network_tx_rate(), "KBytes/s")
|
||||
self.network_traffic_graph.set_property("data_array", self.vm.network_traffic_vector())
|
||||
else:
|
||||
text = "sampling\ndisabled"
|
||||
self.window.get_widget("overview-network-traffic-text").set_markup(text)
|
||||
|
||||
if self.config.is_vmlist_disk_io_visible():
|
||||
text = _rx_tx_text(self.vm.disk_read_rate(), self.vm.disk_write_rate(), "KBytes/s")
|
||||
self.disk_io_graph.set_property("data_array", self.vm.disk_io_vector())
|
||||
else:
|
||||
text = "sampling\ndisabled"
|
||||
self.window.get_widget("overview-disk-usage-text").set_markup(text)
|
||||
|
||||
def refresh_config_cpu(self):
|
||||
self.window.get_widget("state-host-cpus").set_text("%d" % self.vm.get_connection().host_active_processor_count())
|
||||
|
|
|
@ -54,6 +54,11 @@ class vmmDomain(gobject.GObject):
|
|||
self._update_status()
|
||||
self.xml = None
|
||||
|
||||
self.config.on_vmlist_network_traffic_visible_changed(self.toggle_sample_network_traffic)
|
||||
self.toggle_sample_network_traffic()
|
||||
self.config.on_vmlist_disk_io_visible_changed(self.toggle_sample_disk_io)
|
||||
self.toggle_sample_disk_io()
|
||||
|
||||
def get_xml(self):
|
||||
if self.xml is None:
|
||||
self.xml = self.vm.XMLDesc(0)
|
||||
|
@ -155,7 +160,10 @@ class vmmDomain(gobject.GObject):
|
|||
self.lastStatus = status
|
||||
self.emit("status-changed", status)
|
||||
|
||||
def _network_traffic(self):
|
||||
def _sample_network_traffic_dummy(self):
|
||||
return 0, 0
|
||||
|
||||
def _sample_network_traffic(self):
|
||||
rx = 0
|
||||
tx = 0
|
||||
for netdev in self.get_network_devices():
|
||||
|
@ -168,7 +176,10 @@ class vmmDomain(gobject.GObject):
|
|||
logging.error("Error reading interface stats %s" % err)
|
||||
return rx, tx
|
||||
|
||||
def _disk_io(self):
|
||||
def _sample_disk_io_dummy(self):
|
||||
return 0, 0
|
||||
|
||||
def _sample_disk_io(self):
|
||||
rd = 0
|
||||
wr = 0
|
||||
for disk in self.get_disk_devices():
|
||||
|
@ -1065,4 +1076,31 @@ class vmmDomain(gobject.GObject):
|
|||
# Invalidate cached xml
|
||||
self.xml = None
|
||||
|
||||
def toggle_sample_network_traffic(self, ignore1=None, ignore2=None, ignore3=None, ignore4=None):
|
||||
if self.config.is_vmlist_network_traffic_visible():
|
||||
if len(self.record) > 1:
|
||||
# resample the current value before calculating the rate in
|
||||
# self.tick() otherwise we'd get a huge spike when switching
|
||||
# from 0 to bytes_transfered_so_far
|
||||
rxBytes, txBytes = self._sample_network_traffic()
|
||||
self.record[0]["netRxKB"] = rxBytes / 1024
|
||||
self.record[0]["netTxKB"] = txBytes / 1024
|
||||
self._network_traffic = self._sample_network_traffic
|
||||
else:
|
||||
self._network_traffic = self._sample_network_traffic_dummy
|
||||
|
||||
def toggle_sample_disk_io(self, ignore1=None, ignore2=None, ignore3=None, ignore4=None):
|
||||
if self.config.is_vmlist_disk_io_visible():
|
||||
if len(self.record) > 1:
|
||||
# resample the current value before calculating the rate in
|
||||
# self.tick() otherwise we'd get a huge spike when switching
|
||||
# from 0 to bytes_transfered_so_far
|
||||
rdBytes, wrBytes = self._sample_disk_io()
|
||||
self.record[0]["diskRdKB"] = rdBytes / 1024
|
||||
self.record[0]["diskWrKB"] = wrBytes / 1024
|
||||
self._disk_io = self._sample_disk_io
|
||||
else:
|
||||
self._disk_io = self._sample_disk_io_dummy
|
||||
|
||||
|
||||
gobject.type_register(vmmDomain)
|
||||
|
|
Loading…
Reference in New Issue