read_proc_stat: substract guest && guest_nice from user && nice time

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
c66ccee46f/plugins/inputs/cpu/cpu.go
This commit is contained in:
Alexandre Derumier 2022-01-10 05:52:58 +01:00 committed by Thomas Lamprecht
parent 5224b31bbd
commit c140206bf8

View File

@ -169,8 +169,8 @@ sub read_proc_stat {
if (my $fh = IO::File->new ("/proc/stat", "r")) { if (my $fh = IO::File->new ("/proc/stat", "r")) {
while (defined (my $line = <$fh>)) { 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+)|) { 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->{user} = $1 - $9;
$res->{nice} = $2; $res->{nice} = $2 - $10;
$res->{system} = $3; $res->{system} = $3;
$res->{idle} = $4; $res->{idle} = $4;
$res->{used} = $1+$2+$3; $res->{used} = $1+$2+$3;
@ -191,7 +191,7 @@ sub read_proc_stat {
my $ctime = gettimeofday; # floating point time in seconds 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->{total} = $res->{user}
+ $res->{nice} + $res->{nice}
+ $res->{system} + $res->{system}
@ -199,7 +199,9 @@ sub read_proc_stat {
+ $res->{irq} + $res->{irq}
+ $res->{softirq} + $res->{softirq}
+ $res->{steal} + $res->{steal}
+ $res->{idle}; + $res->{idle}
+ $res->{guest}
+ $res->{guest_nice};
$res->{ctime} = $ctime; $res->{ctime} = $ctime;
$res->{cpu} = 0; $res->{cpu} = 0;