mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
fix(computes): a host's CPU chart counts I/O wait as idle, and its memory in GiB
The CPU in use was the share of time not idle, with I/O wait counted as busy: a host that only waited for its disks showed 100% CPU in use. Time waiting for I/O is idle now: no CPU runs then. The memory chart divided by 1024³ and labelled the values GB; it says GiB now.
This commit is contained in:
parent
1f6cc15ddf
commit
81d183f802
4 changed files with 15 additions and 5 deletions
|
|
@ -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"])
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue