* [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
* Re: [pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly
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
0 siblings, 1 reply; 3+ messages in thread
From: Fiona Ebner @ 2023-06-23 11:54 UTC (permalink / raw)
To: Proxmox VE development discussion, Maximiliano Sandoval
Am 20.06.23 um 17:46 schrieb Maximiliano Sandoval:
> When running `pct status VMID` the variable
Issue is only present with --verbose.
> $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.
>
qm would have the same issue, but there, we don't even output a line for
"cpu:" ;)
IMHO, the average of the CPU usage across the whole uptime is not what
most people would expect this value to be. Maybe we should just remove
the line from the output like in qm (technically a breaking change) or
maybe query the CPU stats twice with a small time window in between?
No matter what approach we go for, the behavior of qm and pct should be
made consistent here (if no good reason against it pops up).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pve-devel] [PATCH container] fix #4765: lxc: report cpu usage correctly
2023-06-23 11:54 ` Fiona Ebner
@ 2023-06-24 15:39 ` Thomas Lamprecht
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2023-06-24 15:39 UTC (permalink / raw)
To: Proxmox VE development discussion, Fiona Ebner, Maximiliano Sandoval
Am 23/06/2023 um 13:54 schrieb Fiona Ebner:
> IMHO, the average of the CPU usage across the whole uptime is not what
> most people would expect this value to be.
Yeah, this is really not that useful in most cases.
> Maybe we should just remove the line from the output like in qm (technically
> a breaking change)
Luckily we have a more pragmatic approach to breaking changes that isn't
strictly bound by technicalities.
So yes, as it was hardcoded 0 and thus completely useless I'd also just drop
it. You can 100% redirect all fault to me if somebody complaints.
^ 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