Revert "Merge branch..."

This reverts merge request !5555
This commit is contained in:
Daniel Rodriguez 2023-03-03 10:11:35 +00:00
parent 62ae32335d
commit 6f974508f0
2 changed files with 59 additions and 87 deletions

View File

@ -1,5 +1,4 @@
<?php <?php
/** /**
* Auxiliary functions to manage servers. * Auxiliary functions to manage servers.
* *
@ -45,7 +44,7 @@ function servers_get_server($id_server, $filter=false, $fields=false)
return false; return false;
} }
if (!is_array($filter)) { if (! is_array($filter)) {
$filter = []; $filter = [];
} }
@ -146,6 +145,7 @@ function servers_get_total_modules()
); );
return $modules; return $modules;
} }
@ -1017,57 +1017,40 @@ function servers_get_info($id_server=-1)
// Remote servers LAG Calculation (server_type != 0). // Remote servers LAG Calculation (server_type != 0).
if ($server['server_type'] != 0) { if ($server['server_type'] != 0) {
// MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations.
$sql = sprintf( $result = db_get_row_sql(
'SELECT COUNT(tam.id_agente_modulo) AS module_lag, 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag,
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag"
FROM ( FROM tagente_estado, tagente_modulo, tagente
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo WHERE utimestamp > 0
FROM tagente_estado AND tagente.disabled = 0
WHERE tagente_estado.current_interval > 0 AND tagente.id_agente = tagente_estado.id_agente
AND tagente_estado.last_execution_try > 0 AND tagente_modulo.disabled = 0
AND tagente_estado.running_by = %d AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
) tae AND current_interval > 0
JOIN ( AND running_by = '.$server['id_server'].'
SELECT tagente_modulo.id_agente_modulo AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
FROM tagente_modulo LEFT JOIN tagente AND (UNIX_TIMESTAMP() - utimestamp) > current_interval'
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']
); );
} else { } else {
// Local/Dataserver server LAG calculation. // Local/Dataserver server LAG calculation.
// MySQL 8.0 has function lag(). So, lag must be enclosed in quotations. // MySQL 8.0 has function lag(). So, lag must be enclosed in quotations.
$sql = sprintf( $result = db_get_row_sql(
'SELECT COUNT(tam.id_agente_modulo) AS module_lag, 'SELECT COUNT(tagente_modulo.id_agente_modulo) AS module_lag,
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" AVG(UNIX_TIMESTAMP() - utimestamp - current_interval) AS "lag"
FROM ( FROM tagente_estado, tagente_modulo, tagente
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo WHERE utimestamp > 0
FROM tagente_estado AND tagente.disabled = 0
WHERE tagente_estado.current_interval > 0 AND tagente.id_agente = tagente_estado.id_agente
AND tagente_estado.last_execution_try > 0 AND tagente_modulo.disabled = 0
AND tagente_estado.running_by = %d AND tagente_modulo.id_tipo_modulo < 5
) tae AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
JOIN ( AND current_interval > 0
SELECT tagente_modulo.id_agente_modulo AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
FROM tagente_modulo LEFT JOIN tagente AND running_by = '.$server['id_server'].'
ON tagente_modulo.id_agente = tagente.id_agente AND (UNIX_TIMESTAMP() - utimestamp) > (current_interval * 1.1)'
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']
); );
} }
$result = db_get_row_sql($sql);
// Lag over current_interval * 2 is not lag, // Lag over current_interval * 2 is not lag,
// it's a timed out module. // it's a timed out module.
if (!empty($result['lag'])) { if (!empty($result['lag'])) {
@ -1154,11 +1137,11 @@ function servers_check_remote_config($server_name)
$config['remote_config'] $config['remote_config']
).'/conf/'.$server_md5.'.srv.conf'; ).'/conf/'.$server_md5.'.srv.conf';
if (!isset($filenames['conf'])) { if (! isset($filenames['conf'])) {
return false; return false;
} }
if (!isset($filenames['md5'])) { if (! isset($filenames['md5'])) {
return false; return false;
} }

View File

@ -5629,48 +5629,37 @@ sub pandora_server_statistics ($$) {
if ($server->{"server_type"} != DATASERVER){ if ($server->{"server_type"} != DATASERVER){
$lag_row = get_db_single_row ($dbh, $lag_row = get_db_single_row ($dbh,
"SELECT COUNT(tam.id_agente_modulo) AS module_lag, "SELECT COUNT(tam.id_agente_modulo) AS module_lag, AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS lag
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" FROM (
FROM ( SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo FROM tagente_estado
FROM tagente_estado WHERE tagente_estado.current_interval > 0
WHERE tagente_estado.current_interval > 0 AND tagente_estado.last_execution_try > 0
AND tagente_estado.last_execution_try > 0 AND tagente_estado.running_by = ?
AND tagente_estado.running_by = ? ) tae
) tae JOIN (
JOIN ( SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag
SELECT tagente_modulo.id_agente_modulo FROM tagente_modulo LEFT JOIN tagente
FROM tagente_modulo LEFT JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente
ON tagente_modulo.id_agente = tagente.id_agente WHERE tagente.disabled = 0
WHERE tagente.disabled = 0 AND tagente_modulo.disabled = 0
AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo < 5
) tam ) tam
ON tae.id_agente_modulo = tam.id_agente_modulo ON tae.id_agente_modulo = tam.id_agente_modulo
WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) > (tae.current_interval) WHERE (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)
AND (UNIX_TIMESTAMP() - tae.last_execution_try) < ( tae.current_interval * 10)", $server->{"id_server"}); AND (tam.flag = 1 OR (UNIX_TIMESTAMP() - tae.last_execution_try) > tae.current_interval)", $server->{"id_server"});
} }
# Dataserver LAG calculation: # Dataserver LAG calculation:
else { else {
$lag_row = get_db_single_row ($dbh, "SELECT COUNT(tam.id_agente_modulo) AS module_lag, $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
AVG(UNIX_TIMESTAMP() - tae.last_execution_try - tae.current_interval) AS "lag" FROM tagente_estado, tagente_modulo
FROM ( WHERE utimestamp > 0
SELECT tagente_estado.last_execution_try, tagente_estado.current_interval, tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0
FROM tagente_estado AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
WHERE tagente_estado.current_interval > 0 AND current_interval > 0
AND tagente_estado.last_execution_try > 0 AND running_by = ?
AND tagente_estado.running_by = ? AND (UNIX_TIMESTAMP() - utimestamp) < ( current_interval * 10)
) tae AND (UNIX_TIMESTAMP() - utimestamp) > current_interval", $server->{"id_server"});
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'}; $server->{"module_lag"} = $lag_row->{'module_lag'};