diff --git a/computes/tests/test_cpu_graph.py b/computes/tests/test_cpu_graph.py index ee3142ee..992adf51 100644 --- a/computes/tests/test_cpu_graph.py +++ b/computes/tests/test_cpu_graph.py @@ -159,6 +159,6 @@ class GraphScriptTestCase(TestCase): # a host that could not be read leaves a gap and keeps the memory axis self.assertEqual((result["mem"], result["memMax"]), ([1, None], 2)) # the readings in words, and since when they are not updated - self.assertEqual(result["shown"], ["3 %", "1 / 2 GB", "Updated at t."]) + self.assertEqual(result["shown"], ["3 %", "1 / 2 GiB", "Updated at t."]) self.assertEqual(result["state"], "Not updated since t.") self.assertTrue(result["label"].endswith(": 3 % (average over 5.1 s)"), result["label"]) diff --git a/static/js/host_graphs.js b/static/js/host_graphs.js index 0543c790..93304d57 100644 --- a/static/js/host_graphs.js +++ b/static/js/host_graphs.js @@ -9,11 +9,12 @@ var cpuChart = lineChart(document.getElementById("cpuChart"), "%", [state.datase return span ? text + ' (' + state.dataset.averageOver + ' ' + span + ' s)' : text; }, }); -var memChart = lineChart(document.getElementById("memChart"), "GB", [state.dataset.usage]); +var memChart = lineChart(document.getElementById("memChart"), "GiB", [state.dataset.usage]); var cpuNow = document.getElementById("cpu_now"); var memNow = document.getElementById("mem_now"); var lastUpdate = "–"; +// bytes in GiB (1024³), one decimal function gb(bytes) { return Math.round(bytes / 107374182.4) / 10; } @@ -41,7 +42,7 @@ pollWhileVisible(5000, function () { if (data.memdata.total) { memChart.options.scales.y.max = gb(data.memdata.total); addPoint(memChart, data.timeline, [gb(data.memdata.usage)]); - memNow.textContent = gb(data.memdata.usage) + " / " + gb(data.memdata.total) + " GB"; + memNow.textContent = gb(data.memdata.usage) + " / " + gb(data.memdata.total) + " GiB"; } else { addPoint(memChart, data.timeline, [null]); } diff --git a/vrtManager/hostdetails.py b/vrtManager/hostdetails.py index ac4ed16b..56107f9b 100644 --- a/vrtManager/hostdetails.py +++ b/vrtManager/hostdetails.py @@ -65,9 +65,10 @@ class wvmHostDetails(wvmConnect): return {"total": None, "usage": None, "percent": None} def _cpu_times(self): - """(idle, total) nanoseconds of all host CPUs, from one reading.""" + """(idle, total) nanoseconds of all host CPUs, from one reading. Time + waiting for I/O is idle: no CPU runs then, it only waits for disks.""" stats = self.wvm.getCPUStats(VIR_NODE_CPU_STATS_ALL_CPUS, 0) - return stats["idle"], sum(stats.get(name, 0) for name in CPU_TIMES) + return stats["idle"] + stats.get("iowait", 0), sum(stats.get(name, 0) for name in CPU_TIMES) def get_cpu_usage(self, previous=None): """ diff --git a/vrtManager/tests/test_host_reads.py b/vrtManager/tests/test_host_reads.py index 8ee95b02..c4f3ce59 100644 --- a/vrtManager/tests/test_host_reads.py +++ b/vrtManager/tests/test_host_reads.py @@ -337,6 +337,14 @@ class CpuUsageTestCase(UnitTestCase): # total = kernel + user + idle + iowait; guest (inside user) and utilization are left out self.assertEqual(usage, {"usage": 70.0, "sample": (130, 200, 105.0), "window": 5.0}) + def test_time_waiting_for_disks_is_not_cpu_in_use(self, clock): + # a host that only waits for its disks: no CPU runs + clock.monotonic.return_value = 105.0 + h = wvmHostDetails.__new__(wvmHostDetails) + h.wvm = MagicMock() + h.wvm.getCPUStats.return_value = {"kernel": 0, "user": 0, "idle": 100, "iowait": 100} + self.assertEqual(h.get_cpu_usage(previous=(100, 100, 100.0))["usage"], 0.0) + def test_over_one_second_without_a_sample(self, clock): clock.monotonic.side_effect = [10.0, 11.0] h = host((100, 100), (110, 190))