[pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly
Maximiliano Sandoval
m.sandoval at proxmox.com
Tue Jun 20 17:46:08 CEST 2023
When running `pct status VMID` the variable
$last_proc_vmid_stat->{$vmid} is not set and pct reports no cpu usage.
We address this by computing the used cpu time over the total uptime of
the container.
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
src/PVE/LXC.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index a531ea5..17a7cd7 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -276,10 +276,13 @@ sub vmstatus {
my $old = $last_proc_vmid_stat->{$vmid};
if (!$old) {
+ my $uptime_ms = $d->{uptime} * $cpucount * 1000.0;
+ $d->{cpu} = (($used_ms / $uptime_ms) * $cpucount) / $d->{cpus};
+
$last_proc_vmid_stat->{$vmid} = {
time => $cdtime,
used => $used_ms,
- cpu => 0,
+ cpu => $d->{cpu},
};
next;
}
--
2.39.2
More information about the pve-devel
mailing list