From afb537422ebe3dc0721793b4ba38838fd760af42 Mon Sep 17 00:00:00 2001 From: Calvo Date: Wed, 15 Feb 2023 11:10:45 +0100 Subject: [PATCH] Fix non dataserver lag calculation --- pandora_server/lib/PandoraFMS/Core.pm | 30 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d2a5a79580..3e2e28b5c0 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5628,16 +5628,26 @@ sub pandora_server_statistics ($$) { # Non-dataserver LAG calculation: if ($server->{"server_type"} != DATASERVER){ - $lag_row = get_db_single_row ($dbh, "SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS lag - FROM tagente_estado, tagente_modulo - WHERE utimestamp > 0 - AND tagente_modulo.disabled = 0 - AND tagente_modulo.id_tipo_modulo < 5 - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - AND current_interval > 0 - AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) - AND running_by = ? - AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)", $server->{"id_server"}); + $lag_row = get_db_single_row ($dbh, + "SELECT COUNT(tam.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS lag + FROM ( + SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo + FROM tagente_estado + WHERE tagente_estado.current_interval > 0 + AND tagente_estado.last_execution_try > 0 + AND tagente_estado.running_by = ? + ) tae + JOIN ( + SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag + FROM tagente_modulo LEFT JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.disabled = 0 + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_tipo_modulo < 5 + ) tam + ON tae.id_agente_modulo = tam.id_agente_modulo + WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10) + AND (tam.flag = 1 OR (UNIX_TIMESTAMP() - tae.last_execution_try) > tae.current_interval);", $server->{"id_server"}); } # Dataserver LAG calculation: else {