]> git.proxmox.com Git - pve-common.git/commitdiff
ProcFSTools: read_proc_stat: add more cpu stats from /proc/stat
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 28 Jul 2021 12:12:43 +0000 (14:12 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 29 Jul 2021 08:29:05 +0000 (10:29 +0200)
those fields might be interesting to users. At the moment, this is
only used in the external metrics export.

These fields exist in the kernel since:
* irq - 2.6.0
* softirq - 2.6.0
* steal - 2.6.11
* guest - 2.6.24
* guest_nice - 2.6.33

so they must all exist

also add a 'total' field which simply sums up the (non-guest) fields

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/ProcFSTools.pm

index ff30e4bfaf8df985cb1d667777363451dd0ad606..a75274a9faf03130c41376ec329a07098c4a58c6 100644 (file)
@@ -168,13 +168,18 @@ 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|) {
+           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->{system} = $3;
                $res->{idle} = $4;
                $res->{used} = $1+$2+$3;
                $res->{iowait} = $5;
+               $res->{irq} = $6;
+               $res->{softirq} = $7;
+               $res->{steal} = $8;
+               $res->{guest} = $9;
+               $res->{guest_nice} = $10;
            } elsif ($line =~ m|^cpu\d+\s|) {
                $cpucount++;
            }
@@ -186,6 +191,16 @@ sub read_proc_stat {
 
     my $ctime = gettimeofday; # floating point time in seconds
 
+    # the sum of all (non-guest) fields
+    $res->{total} = $res->{user}
+       + $res->{nice}
+       + $res->{system}
+       + $res->{iowait}
+       + $res->{irq}
+       + $res->{softirq}
+       + $res->{steal}
+       + $res->{idle};
+
     $res->{ctime} = $ctime;
     $res->{cpu} = 0;
     $res->{wait} = 0;