diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 649df85725..a58342dddb 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -1017,40 +1017,58 @@ function servers_get_info($id_server=-1) // Remote servers LAG Calculation (server_type != 0). if ($server['server_type'] != 0) { // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. - $result = db_get_row_sql( - 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, - AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag" - FROM tagente_estado, tagente_modulo, tagente - WHERE utimestamp > 0 - AND tagente.disabled = 0 - AND tagente.id_agente = tagente_estado.id_agente + $sql = sprintf( + '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 = %d + ) tae + JOIN ( + SELECT tagente_modulo.id_agente_modulo + 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_agente_modulo = tagente_estado.id_agente_modulo - AND current_interval > 0 - AND running_by = '.$server['id_server'].' - AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) - AND (UNIX_TIMESTAMP() - utimestamp) > current_interval' + ) tam + ON tae.id_agente_modulo = tam.id_agente_modulo + WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) + AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)', + $server['id_server'] ); } else { // Local/Dataserver server LAG calculation. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. - $result = db_get_row_sql( - 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag, - AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag" - FROM tagente_estado, tagente_modulo, tagente - WHERE utimestamp > 0 - AND tagente.disabled = 0 - AND tagente.id_agente = tagente_estado.id_agente + $sql = sprintf( + '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 = %d + ) tae + JOIN ( + SELECT tagente_modulo.id_agente_modulo + 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 - 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 = '.$server['id_server'].' - AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)' + ) tam + ON tae.id_agente_modulo = tam.id_agente_modulo + WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval * 1.1) + AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)', + $server['id_server'] ); } + $result = db_get_row_sql($sql); + // Lag over current_interval * 2 is not lag, // it's a timed out module. if (!empty($result['lag'])) { diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 04fd172019..b911f05b50 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5627,39 +5627,56 @@ sub pandora_server_statistics ($$) { # Non-dataserver LAG calculation: if ($server->{"server_type"} != DATASERVER){ - - $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 + $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"}); - } + 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 + FROM tagente_modulo LEFT JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + WHERE tagente.disabled = 0 + AND tagente_modulo.disabled = 0 + ) tam + ON tae.id_agente_modulo = tam.id_agente_modulo + WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) + AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", + $server->{"id_server"} + ); +} # Dataserver LAG calculation: else { - $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_agente_modulo = tagente_estado.id_agente_modulo - AND current_interval > 0 - AND running_by = ? - AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10) - AND (UNIX_TIMESTAMP() - utimestamp) > current_interval", $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 + 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 * 1.1) + AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", + $server->{"id_server"} + ); } $server->{"module_lag"} = $lag_row->{'module_lag'};