Merge branch 'ent-2908-lentitud-vista-tactica-cuando-hay-millones-de-eventos' into 'develop'

Improve performance on tactical view with a lot of events

See merge request artica/pandorafms!1857
This commit is contained in:
vgilc 2018-10-25 10:32:11 +02:00
commit 2b6e8473dc
5 changed files with 194 additions and 193 deletions

View File

@ -38,6 +38,9 @@ $get_event_name = (bool) get_parameter ('get_event_name');
$meta = get_parameter ('meta', 0);
$history = get_parameter ('history', 0);
$table_events = get_parameter('table_events', 0);
$total_events = (bool)get_parameter('total_events');
$total_event_graph = (bool)get_parameter('total_event_graph');
$graphic_event_group = (bool)get_parameter('graphic_event_group');
if ($get_event_name) {
$event_id = get_parameter ('event_id');
@ -605,4 +608,37 @@ if ($get_list_events_agents) {
echo $returned_list;
return;
}
if ($total_events) {
global $config;
$sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento ';
if ($config['event_view_hr']) {
$sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - ' . $config['event_view_hr'] * SECONDS_1HOUR . ')';
}
$system_events = db_get_value_sql($sql_count_event);
echo $system_events;
return;
}
if ($total_event_graph) {
global $config;
require_once($config["homedir"] . '/include/functions_graph.php');
$prueba = grafico_eventos_total("", 280, 150, false, true);
echo $prueba;
return;
}
if ($graphic_event_group) {
global $config;
require_once($config["homedir"] . '/include/functions_graph.php');
$prueba = grafico_eventos_grupo(280, 150, "", false, true);
echo $prueba;
return;
}
?>

View File

@ -851,21 +851,10 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret
$filter = '1 = 1';
}
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ("SELECT DISTINCT tevento.*
FROM tevento LEFT JOIN tagent_secondary_group tasg ON tevento.id_agente = tasg.id_agent
WHERE %s %s
ORDER BY utimestamp DESC LIMIT %d", $agent_condition, $filter, $limit);
break;
case "oracle":
$sql = sprintf ("SELECT *
FROM tevento
WHERE %s %s AND rownum <= %d
ORDER BY utimestamp DESC", $agent_condition, $filter, $limit);
break;
}
$result = db_get_all_rows_sql ($sql);
@ -997,8 +986,6 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret
$data[4] = "<a class='$myclass' href='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=".$event["id_agente"]."'>".
agents_get_alias($event["id_agente"]). "</A>";
// ui_print_agent_name ($event["id_agente"], true, 25, '', true);
// for System or SNMP generated alerts
}
elseif ($event["event_type"] == "system") {

View File

@ -2719,10 +2719,8 @@ function graph_events_validated($width = 300, $height = 200, $extra_filters = ar
* @param integer width pie graph width
* @param integer height pie graph height
* @param string url
* @param bool if the graph required is or not for metaconsole
* @param bool if the graph required is or not for history table
*/
function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = false, $history = false, $noWaterMark = true) {
function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $noWaterMark = true, $time_limit = false) {
global $config;
global $graphic_type;
@ -2752,27 +2750,18 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
$url = str_replace(
'SELECT_id_agente_modulo', 'SELECT id_agente_modulo', $url);
// Choose the table where search if metaconsole or not
if ($meta) {
if ($history) {
$event_table = 'tmetaconsole_event_history';
}
else {
$event_table = 'tmetaconsole_event';
}
$field_extra = ', agent_name';
$groupby_extra = ', server_id';
}
else {
$event_table = 'tevento';
$field_extra = '';
$groupby_extra = '';
}
// Add tags condition to filter
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
if ($time_limit && $config['event_view_hr']) {
$tags_condition .= " AND utimestamp > (UNIX_TIMESTAMP(NOW()) - " .
$config['event_view_hr'] * SECONDS_1HOUR . ")";
}
//This will give the distinct id_agente, give the id_grupo that goes
//with it and then the number of times it occured. GROUP BY statement
//is required if both DISTINCT() and COUNT() are in the statement
@ -2804,14 +2793,9 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
if ($row["id_agente"] == 0) {
$system_events += $row["count"];
}
else {
if ($meta) {
$name = mb_substr (io_safe_output($row['agent_name']), 0, 25)." (".$row["count"].")";
}
else {
$alias = agents_get_alias($row["id_agente"]);
$name = mb_substr($alias, 0, 25)." #".$row["id_agente"]." (".$row["count"].")";
}
$data[$name] = $row["count"];
}
}
@ -2823,13 +2807,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
$data[$name] = $system_events;
}
/*
if ($other_events > 0) {
$name = __('Other')." (".$other_events.")";
$data[$name] = $other_events;
}
*/
// Sort the data
arsort($data);
if ($noWaterMark) {
@ -2851,7 +2828,7 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta =
*
* @param string filter Filter for query in DB
*/
function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWaterMark = true) {
function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWaterMark = true, $time_limit = false) {
global $config;
global $graphic_type;
@ -2860,12 +2837,15 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat
// Add tags condition to filter
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
$filter .= $tags_condition;
if ($time_limit && $config['event_view_hr']) {
$filter .= " AND utimestamp > (UNIX_TIMESTAMP(NOW()) - " . $config['event_view_hr'] * SECONDS_1HOUR . ")";
}
$data = array ();
$legend = array ();
$total = 0;
$where = '';
$where = "WHERE 1=1";
if (!users_is_admin()) {
$where = 'WHERE event_type NOT IN (\'recon_host_detected\', \'system\',\'error\', \'new_agent\', \'configuration_change\')';
}
@ -2876,7 +2856,6 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat
ON tevento.id_agente = tasg.id_agent
%s %s
GROUP BY criticity ORDER BY events DESC", $where , $filter);
$criticities = db_get_all_rows_sql ($sql, false, false);
if (empty($criticities)) {

View File

@ -10065,7 +10065,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
return $data_colors;
}
function reporting_get_stats_servers($tiny = true) {
function reporting_get_stats_servers() {
global $config;
$server_performance = servers_get_performance();
@ -10101,30 +10101,6 @@ function reporting_get_stats_servers($tiny = true) {
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
if ($tiny) {
$tdata = array();
$tdata[0] = html_print_image('images/network.png', true, array('title' => __('Remote modules'), 'width' => '25px'));
$tdata[1] = '<span class="big_data">' . format_numeric($server_performance ["total_remote_modules"]) . '</span>';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years.
*/
$tdata[2] = '<span class="med_data">' . format_numeric($server_performance ["remote_modules_rate"], 2) . '</span>';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec </span>';
if($server_performance ["total_remote_modules"]>10000 && !enterprise_installed()){
$tdata[4] = "<div id='agentsmodal' class='publienterprise' title='Community version' style='text-align:left;'><img data-title='Enterprise version' class='img_help forced_title' data-use_title_for_force_title='1' src='images/alert_enterprise.png'></div>";
}
else{
$tdata[4] = '&nbsp;';
}
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
else {
if (isset($server_performance ["total_network_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px'));
@ -10206,28 +10182,11 @@ You can of course remove the warnings, that's why we include the source and do n
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
switch ($config["dbtype"]) {
case "mysql":
$system_events = db_get_value_sql(
'SELECT SQL_NO_CACHE COUNT(id_evento)
FROM tevento');
break;
case "postgresql":
case "oracle":
$system_events = db_get_value_sql(
'SELECT COUNT(id_evento)
FROM tevento');
break;
}
$tdata = array();
$tdata[0] = html_print_image('images/lightning_go.png', true,
array('title' => __('Total events'), 'width' => '25px'));
$tdata[1] = '<span class="big_data">' .
format_numeric($system_events) . '</span>';
$tdata[1] = '<span class="big_data" id="total_events">' .
html_print_image('images/spinner.gif',true) . '</span>';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
@ -10236,15 +10195,12 @@ You can of course remove the warnings, that's why we include the source and do n
if($system_events > 50000 && !enterprise_installed()){
$tdata[2] = "<div id='monitoreventsmodal' class='publienterprise' title='Community version' style='text-align:left'><img data-title='Enterprise version' class='img_help forced_title' data-use_title_for_force_title='1' src='images/alert_enterprise.png'></div>";
}
else{
} else {
$tdata[3] = "&nbsp;";
}
$table_srv->colspan[count($table_srv->data)][1] = 2;
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
$output = '<fieldset class="databox tactical_set">
<legend>' .
@ -10252,6 +10208,20 @@ You can of course remove the warnings, that's why we include the source and do n
'</legend>' .
html_print_table($table_srv, true) . '</fieldset>';
$output .= '<script type="text/javascript">';
$output .= '$(document).ready(function () {';
$output .= 'var parameters = {};';
$output .= 'parameters["page"] = "include/ajax/events";';
$output .= 'parameters["total_events"] = 1;';
$output .= '$.ajax({type: "GET",url: "ajax.php",data: parameters,';
$output .= 'success: function(data) {';
$output .= '$("#total_events").text(data);';
$output .= '}';
$output .= '});';
$output .= '});';
$output .= '</script>';
return $output;
}

View File

@ -163,7 +163,7 @@ $table->rowclass[] = '';
// Server performance
// ---------------------------------------------------------------------
if ($is_admin) {
$table->data[4][0] = reporting_get_stats_servers(false);
$table->data[4][0] = reporting_get_stats_servers();
$table->rowclass[] = '';
}
@ -183,6 +183,11 @@ if (check_acl($config['id_user'],0,'ER')) {
if (!empty($tags_condition)) {
$event_filter .= " AND ($tags_condition)";
}
if ($config['event_view_hr']) {
$event_filter .= " AND utimestamp > (UNIX_TIMESTAMP(NOW()) - " . $config['event_view_hr'] * SECONDS_1HOUR . ")";
}
$events = events_print_event_table ($event_filter, 10, "100%",true,false,true);
ui_toggle($events, __('Latest events'),false,false);
}
@ -196,20 +201,44 @@ if ($is_admin) {
}
$out = '<table cellpadding=0 cellspacing=0 class="databox pies" style="margin-top:15px;" width=100%><tr><td>';
$out .= '<fieldset class="databox tactical_set">
$out .= '<fieldset class="databox tactical_set" id="total_event_graph">
<legend>' .
__('Event graph') .
'</legend>' .
grafico_eventos_total("", 280, 150, false) . '</fieldset>';
html_print_image('images/spinner.gif',true,array('id' => 'spinner_total_event_graph')) . '</fieldset>';
$out .="</td><td>";
$out .= '<fieldset class="databox tactical_set">
$out .= '<fieldset class="databox tactical_set" id="graphic_event_group">
<legend>' .
__('Event graph by agent') .
'</legend>' .
grafico_eventos_grupo(280, 150, "", false, false, false) . '</fieldset>';
html_print_image('images/spinner.gif', true, array('id' => 'spinner_graphic_event_group')) . '</fieldset>';
$out .= '</td></tr></table>';
echo $out;
echo '</td>';
echo '</tr></table>';
?>
<script type="text/javascript">
$(document).ready(function () {
var parameters = {};
parameters["page"] = "include/ajax/events";
parameters["total_event_graph"] = 1;
$.ajax({type: "GET",url: "ajax.php",data: parameters,
success: function(data) {
$("#spinner_total_event_graph").hide();
$("#total_event_graph").append(data);
}
});
delete parameters["total_event_graph"];
parameters["graphic_event_group"] = 1;
$.ajax({type: "GET",url: "ajax.php",data: parameters,
success: function(data) {
$("#spinner_graphic_event_group").hide();
$("#graphic_event_group").append(data);
}
});
});
</script>