public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly
Date: Tue, 20 Jun 2023 17:46:08 +0200	[thread overview]
Message-ID: <20230620154608.338825-1-m.sandoval@proxmox.com> (raw)

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





             reply	other threads:[~2023-06-20 15:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 15:46 Maximiliano Sandoval [this message]
2023-06-23 11:54 ` Fiona Ebner
2023-06-24 15:39   ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230620154608.338825-1-m.sandoval@proxmox.com \
    --to=m.sandoval@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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