[pve-devel] [PATCH pve-common 4/4] read_proc_stat: use total of fields to compute percentage

Alexandre Derumier aderumier at odiso.com
Mon Jan 10 05:53:00 CET 2022


---
 src/PVE/ProcFSTools.pm | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index 10c0cbd..88df5d2 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -214,11 +214,15 @@ sub read_proc_stat {
     if ($diff > 1000) { # don't update too often
 	my $useddiff =  $res->{used} - $last_proc_stat->{used};
 	$useddiff = $diff if $useddiff > $diff;
-	$res->{cpu} = $useddiff/$diff;
+
+	my $totaldiff = $res->{total} - $last_proc_stat->{total};
+	$totaldiff = $diff if $totaldiff > $diff;
+
+	$res->{cpu} = $useddiff/$totaldiff;
 
 	my $waitdiff =  $res->{iowait} - $last_proc_stat->{iowait};
 	$waitdiff = $diff if $waitdiff > $diff;
-	$res->{wait} = $waitdiff/$diff;
+	$res->{wait} = $waitdiff/$totaldiff;
 
 	$last_proc_stat = $res;
     } else {
-- 
2.30.2





More information about the pve-devel mailing list