If we see that the migration to the new pve9- rrd format has been done
or is ongoing (new dir exists), we collect and send out the new format with 
additional
columns for nodes and VMs (guests).

Those are:
Nodes:
* memfree
* membuffers
* memcached
* arcsize
* pressures:
  * cpu some
  * io some
  * io full
  * mem some
  * mem full

VMs:
* memhost (memory consumption of all processes in the guests cgroup, host view)
* pressures:
  * cpu some
  * cpu full
  * io some
  * io full
  * mem some
  * mem full

Signed-off-by: Aaron Lauterer <a.laute...@proxmox.com>
---

Notes:
    this will automatically send the additional columns to the metric
    servers as well. Not sure if that is okay or could be a problem that we
    need to address or at least mention in the release notes.

 PVE/Service/pvestatd.pm | 128 +++++++++++++++++++++++++++++++---------
 1 file changed, 100 insertions(+), 28 deletions(-)

diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index d80c62da..eb4352fa 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -82,6 +82,16 @@ my $cached_kvm_version = '';
 my $next_flag_update_time;
 my $failed_flag_update_delay_sec = 120;
 
+# Checks if RRD files exist in the specified location.
+my $rrd_dir_exists = sub{
+    my ($location) = @_;
+    if (-d "/var/lib/rrdcached/db/${location}") {
+       return 1;
+    } else {
+       return 0;
+    }
+};
+
 sub update_supported_cpuflags {
     my $kvm_version = PVE::QemuServer::kvm_user_version();
 
@@ -173,19 +183,38 @@ sub update_node_status {
 
     my $meminfo = PVE::ProcFSTools::read_meminfo();
 
+    my $pressures = PVE::ProcFSTools::read_pressure();
+
     my $dinfo = df('/', 1);     # output is bytes
     # everything not free is considered to be used
     my $dused = $dinfo->{blocks} - $dinfo->{bfree};
 
     my $ctime = time();
 
-    my $data = $generate_rrd_string->(
-       [$uptime, $sublevel, $ctime, $avg1, $maxcpu, $stat->{cpu}, 
$stat->{wait},
-        $meminfo->{memtotal}, $meminfo->{memused},
-        $meminfo->{swaptotal}, $meminfo->{swapused},
-        $dinfo->{blocks}, $dused, $netin, $netout]
-    );
-    PVE::Cluster::broadcast_rrd("pve2-node/$nodename", $data);
+    my $data;
+    # TODO: switch fully to pve9-node
+    if ($rrd_dir_exists->("pve9-node")) {
+       $data = $generate_rrd_string->(
+           [$uptime, $sublevel, $ctime,  $avg1, $maxcpu, $stat->{cpu},
+               $stat->{wait}, $meminfo->{memtotal}, $meminfo->{memused},
+               $meminfo->{swaptotal}, $meminfo->{swapused}, $dinfo->{blocks},
+               $dused, $netin, $netout, $meminfo->{memavailable},
+               $meminfo->{buffers}, $meminfo->{cached}, $meminfo->{arcsize},
+               $pressures->{cpu}{some}{avg10}, $pressures->{io}{some}{avg10},
+               $pressures->{io}{full}{avg10},
+               $pressures->{memory}{some}{avg10},
+               $pressures->{memory}{full}{avg10}]
+       );
+       PVE::Cluster::broadcast_rrd("pve9-node/$nodename", $data);
+    } else {
+       $data = $generate_rrd_string->(
+           [$uptime, $sublevel, $ctime, $avg1, $maxcpu, $stat->{cpu}, 
$stat->{wait},
+            $meminfo->{memtotal}, $meminfo->{memused},
+            $meminfo->{swaptotal}, $meminfo->{swapused},
+            $dinfo->{blocks}, $dused, $netin, $netout]
+       );
+       PVE::Cluster::broadcast_rrd("pve2-node/$nodename", $data);
+    }
 
     my $node_metric = {
        uptime => $uptime,
@@ -252,17 +281,39 @@ sub update_qemu_status {
        my $data;
        my $status = $d->{qmpstatus} || $d->{status} || 'stopped';
        my $template = $d->{template} ? $d->{template} : "0";
-       if ($d->{pid}) { # running
-           $data = $generate_rrd_string->(
-               [$d->{uptime}, $d->{name}, $status, $template, $ctime, 
$d->{cpus}, $d->{cpu},
-                $d->{maxmem}, $d->{mem}, $d->{maxdisk}, $d->{disk},
-                $d->{netin}, $d->{netout}, $d->{diskread}, $d->{diskwrite}]);
+
+       # TODO: switch fully to pve9-vm
+       if ($rrd_dir_exists->("pve9-vm")) {
+           if ($d->{pid}) { # running
+               $data = $generate_rrd_string->(
+                   [$d->{uptime}, $d->{name}, $status, $template, $ctime,
+                       $d->{cpus}, $d->{cpu}, $d->{maxmem}, $d->{mem},
+                       $d->{maxdisk}, $d->{disk}, $d->{netin}, $d->{netout},
+                       $d->{diskread}, $d->{diskwrite},$d->{memhost},
+                       $d->{pressurecpusome}, $d->{pressurecpufull},
+                       $d->{pressureiosome}, $d->{pressureiofull},
+                       $d->{pressurememorysome}, $d->{pressurememoryfull}]);
+           } else {
+               $data = $generate_rrd_string->(
+                   [0, $d->{name}, $status, $template, $ctime, $d->{cpus},
+                       undef, $d->{maxmem}, undef, $d->{maxdisk}, $d->{disk},
+                       undef, undef, undef, undef,undef, undef, undef, undef,
+                       undef, undef, undef]);
+           }
+           PVE::Cluster::broadcast_rrd("pve9-vm/$vmid", $data);
        } else {
-           $data = $generate_rrd_string->(
-               [0, $d->{name}, $status, $template, $ctime, $d->{cpus}, undef,
-                $d->{maxmem}, undef, $d->{maxdisk}, $d->{disk}, undef, undef, 
undef, undef]);
+           if ($d->{pid}) { # running
+               $data = $generate_rrd_string->(
+                   [$d->{uptime}, $d->{name}, $status, $template, $ctime, 
$d->{cpus}, $d->{cpu},
+                    $d->{maxmem}, $d->{mem}, $d->{maxdisk}, $d->{disk},
+                    $d->{netin}, $d->{netout}, $d->{diskread}, 
$d->{diskwrite}]);
+           } else {
+               $data = $generate_rrd_string->(
+                   [0, $d->{name}, $status, $template, $ctime, $d->{cpus}, 
undef,
+                    $d->{maxmem}, undef, $d->{maxdisk}, $d->{disk}, undef, 
undef, undef, undef]);
+           }
+           PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
        }
-       PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
 
        PVE::ExtMetric::update_all($transactions, 'qemu', $vmid, $d, $ctime, 
$nodename);
     }
@@ -460,20 +511,40 @@ sub update_lxc_status {
        my $d = $vmstatus->{$vmid};
        my $template = $d->{template} ? $d->{template} : "0";
        my $data;
-       if ($d->{status} eq 'running') { # running
-           $data = $generate_rrd_string->(
-               [$d->{uptime}, $d->{name}, $d->{status}, $template,
-                $ctime, $d->{cpus}, $d->{cpu},
-                $d->{maxmem}, $d->{mem},
-                $d->{maxdisk}, $d->{disk},
-                $d->{netin}, $d->{netout},
-                $d->{diskread}, $d->{diskwrite}]);
+       if ($rrd_dir_exists->("pve9-vm")) {
+           if ($d->{pid}) { # running
+               $data = $generate_rrd_string->(
+                   [$d->{uptime}, $d->{name}, $d->{status}, $template, $ctime,
+                       $d->{cpus}, $d->{cpu}, $d->{maxmem}, $d->{mem},
+                       $d->{maxdisk}, $d->{disk}, $d->{netin}, $d->{netout},
+                       $d->{diskread}, $d->{diskwrite}, undef,
+                       $d->{pressurecpusome}, $d->{pressurecpufull},
+                       $d->{pressureiosome}, $d->{pressureiofull},
+                       $d->{pressurememorysome}, $d->{pressurememoryfull}]);
+           } else {
+               $data = $generate_rrd_string->(
+                   [0, $d->{name}, $d->{status}, $template, $ctime,
+                       $d->{cpus}, undef, $d->{maxmem}, undef, $d->{maxdisk},
+                       $d->{disk}, undef, undef, undef, undef, undef, undef,
+                       undef, undef, undef, undef, undef]);
+           }
+           PVE::Cluster::broadcast_rrd("pve9-vm/$vmid", $data);
        } else {
-           $data = $generate_rrd_string->(
-               [0, $d->{name}, $d->{status}, $template, $ctime, $d->{cpus}, 
undef,
-                $d->{maxmem}, undef, $d->{maxdisk}, $d->{disk}, undef, undef, 
undef, undef]);
+           if ($d->{status} eq 'running') { # running
+               $data = $generate_rrd_string->(
+                   [$d->{uptime}, $d->{name}, $d->{status}, $template,
+                    $ctime, $d->{cpus}, $d->{cpu},
+                    $d->{maxmem}, $d->{mem},
+                    $d->{maxdisk}, $d->{disk},
+                    $d->{netin}, $d->{netout},
+                    $d->{diskread}, $d->{diskwrite}]);
+           } else {
+               $data = $generate_rrd_string->(
+                   [0, $d->{name}, $d->{status}, $template, $ctime, 
$d->{cpus}, undef,
+                    $d->{maxmem}, undef, $d->{maxdisk}, $d->{disk}, undef, 
undef, undef, undef]);
+           }
+           PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
        }
-       PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
 
        PVE::ExtMetric::update_all($transactions, 'lxc', $vmid, $d, $ctime, 
$nodename);
     }
@@ -498,6 +569,7 @@ sub update_storage_status {
        my $data = $generate_rrd_string->([$ctime, $d->{total}, $d->{used}]);
 
        my $key = "pve2-storage/${nodename}/$storeid";
+       $key = "pve9-storage/${nodename}/$storeid" if 
$rrd_dir_exists->("pve9-storage");
        PVE::Cluster::broadcast_rrd($key, $data);
 
        PVE::ExtMetric::update_all($transactions, 'storage', $nodename, 
$storeid, $d, $ctime);
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to