From: "DERUMIER, Alexandre" <Alexandre.DERUMIER@groupe-cyllene.com>
To: "pve-devel@lists.proxmox.com" <pve-devel@lists.proxmox.com>
Subject: [pve-devel] host cpu stats: read_proc_stat "used" value don't count all needed fields
Date: Thu, 6 Jan 2022 09:57:23 +0000 [thread overview]
Message-ID: <1f9968a904037b7901b8b66d243395db0cfa34f7.camel@groupe-cyllene.com> (raw)
Hi,
I'm currently comparing the proxmox rrd stats with my other monitoring
tools,
and I still have some missing cpu% in proxmox graphs.
I see that dominic have added missing parsed field recently (but only
for external metric server)
https://git.proxmox.com/?p=pve-
common.git;a=blobdiff;f=src/PVE/ProcFSTools.pm;h=a75274a9faf03130c41376
ec329a07098c4a58c6;hp=ff30e4bfaf8df985cb1d667777363451dd0ad606;hb=5a82e
b712e4c879a271686f07c589fadc0b09185;hpb=576dadb1379da130f4ea77f775ea9bb
985419616
The current code only use
$res->{user} = $1;
$res->{nice} = $2;
$res->{system} = $3;
(so missing at least irq && softirq, in my production server it can be
around 5%)
I found some discussion about correct compute of usage here:
https://stackoverflow.com/questions/23367857/accurate-calculation-of-cpu-usage-given-in-percentage-in-linux
also pointing to htop source code
https://github.com/htop-dev/htop/blob/15652e7b8102e86b3405254405d8ee5d2a239004/linux/LinuxProcessList.c
Also, to compute the total diff, we use
my $diff = ($ctime - $last_proc_stat->{ctime}) * $clock_ticks *
$cpucount;
Seem to be correct (Not sure about different freq scaling by cores) ,
but maybe reusing /proc/stats values could be more accurate ? (we
could also compute value for each separate core for example).
from htop:
// Guest time is already accounted in usertime
usertime = usertime - guest;
nicetime = nicetime - guestnice;
// Fields existing on kernels >= 2.6
// (and RHEL's patched kernel 2.4...)
unsigned long long int idlealltime = idletime + ioWait;
unsigned long long int systemalltime = systemtime + irq +
softIrq;
unsigned long long int virtalltime = guest + guestnice;
unsigned long long int totaltime = usertime + nicetime +
systemalltime + idlealltime + steal + virtalltime;
I'll try to implement this logic, and see the difference vs the current
used value.
reply other threads:[~2022-01-06 9:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1f9968a904037b7901b8b66d243395db0cfa34f7.camel@groupe-cyllene.com \
--to=alexandre.derumier@groupe-cyllene.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal