public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly
@ 2023-06-20 15:46 Maximiliano Sandoval
  2023-06-23 11:54 ` Fiona Ebner
  0 siblings, 1 reply; 3+ messages in thread
From: Maximiliano Sandoval @ 2023-06-20 15:46 UTC (permalink / raw)
  To: pve-devel

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@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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-24 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 15:46 [pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly Maximiliano Sandoval
2023-06-23 11:54 ` Fiona Ebner
2023-06-24 15:39   ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal