]> git.proxmox.com Git - pve-common.git/commitdiff
read_proc_stat: substract guest && guest_nice from user && nice time
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 10 Jan 2022 04:52:58 +0000 (05:52 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 13 Jan 2022 15:03:49 +0000 (16:03 +0100)
user && nice time already include guest value
https://github.com/torvalds/linux/blob/4ec9f7a18/kernel/sched/cputime.c#L151-L158

Other monitoring tools are already substracting theses guest values

https://github.com/htop-dev/htop/blob/main/linux/LinuxProcessList.c
https://github.com/influxdata/telegraf/blob/c66ccee46f47717c399ccc0348d17c95d11f477d/plugins/inputs/cpu/cpu.go

src/PVE/ProcFSTools.pm

index c81613194ed2272bfa9ac3d5ec3e7303f117d341..79d4a4c86d8d1a1df1112d8a68391aa6a7ac2b06 100644 (file)
@@ -169,8 +169,8 @@ 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;
-               $res->{nice} = $2;
+               $res->{user} = $1 - $9;
+               $res->{nice} = $2 - $10;
                $res->{system} = $3;
                $res->{idle} = $4;
                $res->{used} = $1+$2+$3;
@@ -191,7 +191,7 @@ sub read_proc_stat {
 
     my $ctime = gettimeofday; # floating point time in seconds
 
-    # the sum of all (non-guest) fields
+    # the sum of all fields
     $res->{total} = $res->{user}
        + $res->{nice}
        + $res->{system}
@@ -199,7 +199,9 @@ sub read_proc_stat {
        + $res->{irq}
        + $res->{softirq}
        + $res->{steal}
-       + $res->{idle};
+       + $res->{idle}
+       + $res->{guest}
+       + $res->{guest_nice};
 
     $res->{ctime} = $ctime;
     $res->{cpu} = 0;