From: Fabian Ebner <f.ebner@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [RFC pve-common] procfs tools: handle proc/stat without guest values
Date: Fri, 22 Apr 2022 10:15:46 +0200 [thread overview]
Message-ID: <20220422081546.20112-1-f.ebner@proxmox.com> (raw)
PMG is often run as a container, and in certain environments
(Parallels?), the last two values (guest and guest_nice) might not be
present. This led to a division by zero, because the total value was
never updated.
Reported in the community forum:
https://forum.proxmox.com/threads/106896/
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
src/PVE/ProcFSTools.pm | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index 88df5d2..d636427 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -168,9 +168,9 @@ sub read_proc_stat {
if (my $fh = IO::File->new ("/proc/stat", "r")) {
while (defined (my $line = <$fh>)) {
- if ($line =~ m|^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)|) {
- $res->{user} = $1 - $9;
- $res->{nice} = $2 - $10;
+ if ($line =~ m|^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)(?:\s+(\d+)\s+(\d+))?|) {
+ $res->{user} = $1 - ($9 // 0);
+ $res->{nice} = $2 - ($10 // 0);
$res->{system} = $3;
$res->{idle} = $4;
$res->{used} = $1+$2+$3+$6+$7+$8;
@@ -178,8 +178,8 @@ sub read_proc_stat {
$res->{irq} = $6;
$res->{softirq} = $7;
$res->{steal} = $8;
- $res->{guest} = $9;
- $res->{guest_nice} = $10;
+ $res->{guest} = $9 // 0;
+ $res->{guest_nice} = $10 // 0;
} elsif ($line =~ m|^cpu\d+\s|) {
$cpucount++;
}
--
2.30.2
next reply other threads:[~2022-04-22 8:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 8:15 Fabian Ebner [this message]
2022-04-25 7:44 ` Fabian Ebner
2022-06-14 7:44 ` Wolfgang Bumiller
2022-06-14 8:28 ` [pmg-devel] applied: " Fabian Ebner
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=20220422081546.20112-1-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pmg-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