[pve-devel] [PATCH pve-manager 1/4] pvestatd: add broadcast_balancer_stats

Alexandre Derumier aderumier at odiso.com
Wed Jun 1 10:12:46 CEST 2022


broadcast each minute as it'll be average stats

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Service/pvestatd.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index 72445ec0..984877c1 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -79,6 +79,8 @@ sub hup {
 my $cached_kvm_version = '';
 my $next_flag_update_time;
 my $failed_flag_update_delay_sec = 120;
+my $balancer_stats = {};
+my $last_balancer_broadcast_time = 0;
 
 sub update_supported_cpuflags {
     my $kvm_version = PVE::QemuServer::kvm_user_version();
@@ -491,6 +493,20 @@ sub update_sdn_status {
     }
 }
 
+sub broadcast_balancer_stats {
+
+    my $ctime = time();
+
+    if($ctime >= $last_balancer_broadcast_time + 60) {
+
+	PVE::Cluster::broadcast_node_kv(
+	    'balancer-stats',
+	    encode_json($balancer_stats),
+	);
+	$last_balancer_broadcast_time = $ctime;
+    }
+}
+
 my $broadcast_version_info_done = 0;
 my sub broadcast_version_info : prototype() {
     if (!$broadcast_version_info_done) {
@@ -507,6 +523,8 @@ sub update_status {
     # correct list in case of an unexpected crash.
     my $rpcenv = PVE::RPCEnvironment::get();
 
+    $balancer_stats = {};
+
     eval {
 	my $tlist = $rpcenv->active_workers();
 	PVE::Cluster::broadcast_tasklist($tlist);
@@ -534,6 +552,12 @@ sub update_status {
     $err = $@;
     syslog('err', "lxc status update error: $err") if $err;
 
+    eval {
+	broadcast_balancer_stats();
+    };
+    $err = $@;
+    syslog('err', "balancer stats broadcast error: $err") if $err;
+
     eval {
 	rebalance_lxc_containers();
     };
-- 
2.30.2





More information about the pve-devel mailing list