Fixed grown in notifications

Former-commit-id: c563f2388d27d4fffbcfaf34fbd1c4d83ad4ef84
This commit is contained in:
fbsanchez 2019-03-06 19:39:07 +01:00
parent a860b293e3
commit aef10cf649
3 changed files with 66 additions and 5 deletions

View File

@ -962,10 +962,12 @@ class ConsoleSupervisor
{
global $config;
include_once $config['homedir'].'/include/functions_servers.php';
$idx_file = $config['attachment_store'].'/.cron.supervisor.servers.idx';
$MAX_QUEUE = 1500;
$MAX_GROWN = 50;
$total_modules = servers_get_total_modules();
$queue_state = [];
$previous = [];
@ -988,6 +990,13 @@ class ConsoleSupervisor
$key = $queue['id_server'];
$type = $queue['server_type'];
$new_data[$key] = $queue['queued_modules'];
$max_grown = 0;
if (is_array($total_modules)
&& isset($total_modules[$queue['server_type']])
) {
$max_grown = ($total_modules[$queue['server_type']] * 0.40);
}
// Compare queue increments in a not over 900 seconds.
if (empty($previous[$key]['modules'])
@ -998,9 +1007,9 @@ class ConsoleSupervisor
$modules_queued = ($queue['queued_modules'] - $previous[$key]['modules']);
// 50 Modules queued since last check. Or more than 1500 queued.
if ($modules_queued > $MAX_GROWN
|| $queue['queued_modules'] > $MAX_QUEUE
// 40% Modules queued since last check. If any.
if ($max_grown > 0
&& $modules_queued > $max_grown
) {
$msg = 'Queue has grown %d modules. Total %d';
if ($modules_queued <= 0) {

View File

@ -88,6 +88,58 @@ function servers_force_recon_task($id_recon_task)
}
/**
* Retrieves total number of modules per server.
*
* @return array Modules per server (total).
*/
function servers_get_total_modules()
{
$modules = [];
$modules_from_monitors = db_get_all_rows_sql(
'SELECT
tserver.server_type,
count(tagente_estado.id_agente_modulo) as modules_assigned
FROM tserver, tagente_estado, tagente_modulo, tagente
WHERE tagente.disabled=0
AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_modulo.disabled = 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_estado.running_by = tserver.id_server
GROUP BY tserver.server_type;'
);
if ($modules_from_monitors !== false) {
$modules = array_reduce(
$modules_from_monitors,
function ($carry, $item) {
$carry[$item['server_type']] = $item['modules_assigned'];
return $carry;
}
);
}
$modules[SERVER_TYPE_INVENTORY] = db_get_sql(
'SELECT COUNT(tagent_module_inventory.id_agent_module_inventory)
FROM tagente, tagent_module_inventory
WHERE tagente.disabled=0
AND tagent_module_inventory.id_agente = tagente.id_agente'
);
$modules[SERVER_TYPE_EXPORT] = db_get_sql(
'SELECT COUNT(tagente_modulo.id_agente_modulo)
FROM tagente, tagente_modulo
WHERE tagente.disabled=0
AND tagente_modulo.id_agente = tagente.id_agente
AND tagente_modulo.id_export != 0'
);
return $modules;
}
/**
* This function will get several metrics from the database to get info about server performance
*

View File

@ -4411,7 +4411,7 @@ div#dialog_messages table th:last-child {
div#header_discovery {
border-radius: 50%;
box-shadow: 0 0 5px 1px #949494;
box-shadow: 0 0 15px 0px #949494;
width: 9px;
font-weight: bold;
color: #fff;