[pve-devel] [PATCH ha-manager v3 6/6] reduce frequency of useless error logging

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Feb 19 18:41:07 CET 2016


If a service is in the error state we got an not rather useful log
message about every 5 seconds, this sums up rather quickly and is
not quite helpful.

This changes the behaviour so that we get an initial log message
and then once per minute.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

This one is probably the ugliest from this series, I hadn't enough time
to find a better solution yet, input welcome.

 src/PVE/HA/LRM.pm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/PVE/HA/LRM.pm b/src/PVE/HA/LRM.pm
index 0b14c85..68b13ed 100644
--- a/src/PVE/HA/LRM.pm
+++ b/src/PVE/HA/LRM.pm
@@ -361,6 +361,8 @@ sub do_one_iteration {
     return 1;
 }
 
+# for not logging the error state every round
+my $log_error = 0;
 
 sub run_workers {
     my ($self) = @_;
@@ -382,6 +384,8 @@ sub run_workers {
 
 	    my $w = $self->{workers}->{$sid};
 	    if (!$w->{pid}) {
+		my @agent_params = ($sid, $sc->{$sid}, $w->{state}, $w->{target},
+				    $log_error);
 		# only fork if we may else call exec_resource_agent
 		# directly (e.g. for regression tests)
 		if ($max_workers > 0) {
@@ -395,7 +399,7 @@ sub run_workers {
 			# do work
 			my $res = -1;
 			eval {
-			    $res = $self->exec_resource_agent($sid, $sc->{$sid}, $w->{state}, $w->{target});
+			    $res = $self->exec_resource_agent(@agent_params );
 			};
 			if (my $err = $@) {
 			    $haenv->log('err', $err);
@@ -409,7 +413,7 @@ sub run_workers {
 		} else {
 		    my $res = -1;
 		    eval {
-			$res = $self->exec_resource_agent($sid, $sc->{$sid}, $w->{state}, $w->{target});
+			$res = $self->exec_resource_agent(@agent_params);
 			$res = $res << 8 if $res > 0;
 		    };
 		    if (my $err = $@) {
@@ -426,6 +430,9 @@ sub run_workers {
 
 	last if !$count;
 
+	# log errors every 60 seconds
+	$log_error = ($log_error + 1) % 12;
+
 	$haenv->sleep(1);
     }
 
-- 
2.1.4





More information about the pve-devel mailing list