Merge branch '757-full-scale-graph-dev' into 'develop'

757 full scale graph dev

See merge request !552
This commit is contained in:
vgilc 2017-06-06 09:51:04 +02:00
commit aedb440ea2
3 changed files with 119 additions and 66 deletions

View File

@ -569,7 +569,13 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f
if ((!isset($tstart)) || ($tstart === false)) {
// Return data from the begining
$tstart = 0;
// Get first available utimestamp in active DB
$query_first_man_time = " SELECT utimestamp FROM tagente_datos ";
$query_first_man_time .= " WHERE id_agente_modulo = $id_agente_modulo";
$query_first_man_time .= " ORDER BY utimestamp ASC LIMIT 1";
$first_man_time = db_get_all_rows_sql( $query_first_man_time, false);
$tstart = $first_man_time[0]['utimestamp'];
}
if ((!isset($tend)) || ($tend === false)) {
@ -581,7 +587,6 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f
return false;
}
$search_historydb = false;
$table = "tagente_datos";
@ -596,13 +601,11 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f
$table = "tagente_datos_string";
}
// Get first available utimestamp in active DB
$query = " SELECT utimestamp, datos FROM $table ";
$query .= " WHERE id_agente_modulo=$id_agente_modulo AND utimestamp < $tstart";
$query .= " ORDER BY utimestamp DESC LIMIT 1";
$ret = db_get_all_rows_sql( $query , $search_historydb);
if ( ( $ret === false ) || (( isset($ret[0]["utimestamp"]) && ($ret[0]["utimestamp"] > $tstart )))) {
@ -610,6 +613,10 @@ function db_uncompress_module_data($id_agente_modulo, $tstart = false, $tend = f
$search_historydb = true;
$ret = db_get_all_rows_sql( $query , $search_historydb);
if ($ret) {
$tstart = $ret[0]["utimestamp"];
}
}
else {
$first_data["utimestamp"] = $ret[0]["utimestamp"];

View File

@ -232,7 +232,7 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$projection, $avg_only = false, $uncompressed_module = false,
$show_events = false, $show_alerts = false, $show_unknown = false, $baseline = false,
$baseline_data = array(), $events = array(), $series_suffix = '', $start_unknown = false,
$percentil = null) {
$percentil = null, $fullscale = false) {
global $config;
global $chart_extra_data;
@ -253,11 +253,9 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
// Calculate chart data
$last_known = $previous_data;
for ($i = 0; $i <= $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
$total = 0;
$count = 0;
@ -352,9 +350,15 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
}
elseif ($period < SECONDS_1MONTH) {
$time_format = "M \nd H\h";
if ($fullscale) {
$time_format = "M \nd H:i";
}
}
elseif ($period < SECONDS_6MONTHS) {
$time_format = "M \nd H\h";
if ($fullscale) {
$time_format = "M \nd H:i";
}
}
else {
$time_format = "M Y";
@ -373,9 +377,15 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
}
elseif ($period < SECONDS_1MONTH) {
$time_format = "M d H\h";
if ($fullscale) {
$time_format = "M d H:i";
}
}
elseif ($period < SECONDS_6MONTHS) {
$time_format = "M d H\h";
if ($fullscale) {
$time_format = "M d H:i";
}
}
else {
$time_format = "M Y";
@ -496,7 +506,8 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$show_alerts = false, $avg_only = 0, $date = 0, $unit = '',
$baseline = 0, $return_data = 0, $show_title = true, $projection = false,
$adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '',
$show_unknown = false, $percentil = null, $dashboard = false, $vconsole = false,$type_graph='area') {
$show_unknown = false, $percentil = null, $dashboard = false, $vconsole = false,
$type_graph='area', $fullscale = false) {
global $config;
global $chart;
@ -563,13 +574,30 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
}
// Get module data
if ($fullscale) {
$uncompress_data = db_uncompress_module_data((int)$agent_module_id, $datelimit, $date);
$new_data = array();
$index = 0;
foreach ($uncompress_data as $key => $u_data) {
foreach ($u_data['data'] as $key2 => $u_data2) {
if ($u_data2['datos'] != "") {
$new_data[$index]['datos'] = $u_data2['datos'];
$new_data[$index]['utimestamp'] = $u_data2['utimestamp'];
$index++;
}
}
}
$data = $new_data;
}
else {
$data = db_get_all_rows_filter ('tagente_datos',
array ('id_agente_modulo' => (int)$agent_module_id,
"utimestamp > $datelimit",
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'), 'AND', $search_in_history_db);
}
// Get module warning_min and critical_min
$warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id);
@ -654,15 +682,18 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$unit = modules_get_unit($agent_module_id);
}
if ($fullscale) {
$resolution = count($data); //Number of points of the graph
$interval = (int) ($period / $resolution);
}
// Calculate chart data
grafico_modulo_sparse_data_chart ($chart, $chart_data_extra, $long_index,
$data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit,
$projection, $avg_only, $uncompressed_module,
$show_events, $show_alerts, $show_unknown, $baseline,
$baseline_data, $events, $series_suffix, $start_unknown,
$percentil);
$percentil, $fullscale);
// Return chart data and don't draw
if ($return_data == 1) {
@ -791,7 +822,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$only_image = false, $homeurl = '', $ttl = 1, $projection = false,
$adapt_key = '', $compare = false, $show_unknown = false,
$menu = true, $backgroundColor = 'white', $percentil = null,
$dashboard = false, $vconsole = false, $type_graph = 'area') {
$dashboard = false, $vconsole = false, $type_graph = 'area', $fullscale = false) {
global $config;
global $graphic_type;
@ -821,7 +852,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$show_alerts, $avg_only, $date-$period, $unit, $baseline,
$return_data, $show_title, $projection, $adapt_key,
$compare, $series_suffix, $series_suffix_str,
$show_unknown, $percentil, $dashboard, $vconsole,$type_graph);
$show_unknown, $percentil, $dashboard, $vconsole,$type_graph,
$fullscale);
switch ($compare) {
case 'separated':
@ -854,7 +886,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$show_alerts, $avg_only,
$date, $unit, $baseline, $return_data, $show_title,
$projection, $adapt_key, $compare, '', '', $show_unknown,
$percentil, $dashboard, $vconsole,$type_graph);
$percentil, $dashboard, $vconsole, $type_graph, $fullscale);
if ($return_data) {
@ -3584,7 +3616,8 @@ function fs_error_image ($width = 300, $height = 110) {
function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$unit_name, $show_alerts, $avg_only = 0,
$date = 0, $series_suffix = '', $series_suffix_str = '', $show_unknown = false) {
$date = 0, $series_suffix = '', $series_suffix_str = '', $show_unknown = false,
$fullscale = false) {
global $config;
global $chart;
@ -3594,7 +3627,6 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
global $series_type;
global $chart_extra_data;
$chart = array();
$color = array();
$legend = array();
@ -3652,6 +3684,28 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$data = array ();
}
if ($fullscale) {
$all_data = db_uncompress_module_data($agent_module_id, $datelimit, $date);
$new_uncompress_data = array();
$index = 0;
foreach ($all_data as $uncompress_data) {
foreach ($uncompress_data['data'] as $mod_data) {
if ($mod_data['datos'] != "") {
$new_uncompress_data[$index]['datos'] = $mod_data['datos'];
$new_uncompress_data[$index]['utimestamp'] = $mod_data['utimestamp'];
$index++;
}
}
}
$new_uncompress_data[$index - 1]['id_agente_modulo'] = $agent_module_id;
$data = $new_uncompress_data;
$resolution = count($data); //Number of points of the graph
$interval = (int) ($period / $resolution);
}
// Uncompressed module data
if ($uncompressed_module) {
$min_necessary = 1;
@ -3797,12 +3851,15 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
elseif ($period < SECONDS_1MONTH) {
$time_format = 'M d H\h';
if ($fullscale) {
$time_format = 'M d H:i';
}
elseif ($period < SECONDS_6MONTHS) {
$time_format = "M d H\h";
}
else {
$time_format = "M Y";
$time_format = 'M d H\h';
if ($fullscale) {
$time_format = 'M d H:i';
}
}
$timestamp_short = date($time_format, $timestamp);
@ -3832,13 +3889,6 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$series_type['alert'.$series_suffix] = 'points';
}
//The order filling the array is very important to get the same colors
//in legends and graphs!!!
//Boolean graph doesn't have max!!!
/*if (!$avg_only) {
$chart[$timestamp]['max'.$series_suffix] = 0;
}*/
// Data and zeroes (draw a step)
if ($zero == 1 && $count > 0) {
@ -3873,11 +3923,6 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$series_type['sum' . $series_suffix] = 'boolean';
//Boolean graph doesn't have min!!!
/*if (!$avg_only) {
$chart[$timestamp]['min'.$series_suffix] = 0;
}*/
if (!empty($event_ids)) {
$chart_extra_data[count($chart)-1]['events'] = implode(',',$event_ids);
}
@ -3922,12 +3967,18 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
elseif ($period < SECONDS_1MONTH) {
$time_format = 'M d H\h';
if ($fullscale) {
$time_format = 'M d H:i';
}
}
elseif ($period < SECONDS_6MONTHS) {
$time_format = "M d H\h";
}
else {
$time_format = "M Y";
$time_format = 'M d H\h';
if ($fullscale) {
$time_format = 'M d H:i';
}
}
// Flash chart
@ -3944,17 +3995,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$chart_extra_data['legend_alerts'] = $legend['alert'.$series_suffix];
}
if (!$avg_only) {
//Boolean graph doesn't have max!!!
//$legend['max'.$series_suffix] = __('Max').$series_suffix_str .': '.__('Last').': '.$graph_stats['max']['last'].' '.$unit.' ; '.__('Avg').': '.$graph_stats['max']['avg'].' '.$unit.' ; '.__('Max').': '.$graph_stats['max']['max'].' '.$unit.' ; '.__('Min').': '.$graph_stats['max']['min'].' '.$unit;
$legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit;
// Boolean graph doesn't have min!!!
// $legend['min'.$series_suffix] = __('Min').$series_suffix_str .': '.__('Last').': '.number_format($graph_stats['min']['last'], $config['graph_precision']).' '.$unit.' ; '.__('Avg').': '.number_format($graph_stats['min']['avg'], $config['graph_precision']).' '.$unit.' ; '.__('Max').': '.number_format($graph_stats['min']['max'], $config['graph_precision']).' '.$unit.' ; '.__('Min').': '.number_format($graph_stats['min']['min'], $config['graph_precision']).' '.$unit;
}
else {
$legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('Last').': '.remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])).' '.$unit.' ; '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['sum']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['sum']['min'], $config['graph_precision'])).' '.$unit;
}
if ($show_unknown) {
$legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str;
@ -3986,13 +4027,12 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
array('border' => '#999999', 'color' => '#999999',
'alpha' => CHART_DEFAULT_ALPHA);
}
//$color['baseline'.$series_suffix] = array('border' => null, 'color' => '#0097BD', 'alpha' => 10);
}
function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
$width, $height , $title='', $unit_name, $show_alerts, $avg_only = 0, $pure=0,
$date = 0, $only_image = false, $homeurl = '', $adapt_key = '', $compare = false,
$show_unknown = false, $menu = true) {
$show_unknown = false, $menu = true, $fullscale = false) {
global $config;
global $graphic_type;
@ -4013,7 +4053,6 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
else
$unit = $unit_name;
$series_suffix_str = '';
if ($compare !== false) {
$series_suffix = '2';
@ -4021,7 +4060,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
// Build the data of the previous period
grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$unit_name, $show_alerts, $avg_only, $date-$period, $series_suffix,
$series_suffix_str, $show_unknown);
$series_suffix_str, $show_unknown, $fullscale);
switch ($compare) {
case 'separated':
// Store the chart calculated
@ -4047,7 +4086,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
}
grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$unit_name, $show_alerts, $avg_only, $date, '', '', $show_unknown);
$unit_name, $show_alerts, $avg_only, $date, '', '', $show_unknown, $fullscale);
if ($compare === 'overlapped') {
$i = 0;

View File

@ -167,6 +167,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
$time_compare_separated = get_parameter ("time_compare_separated", 0);
$time_compare_overlapped = get_parameter ("time_compare_overlapped", 0);
$unknown_graph = get_parameter_checkbox ("unknown_graph", 1);
$fullscale = get_parameter ("fullscale", 0);
// To avoid the horizontal overflow
$width -= 20;
@ -211,7 +212,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
$width, $height, $label_graph, $unit, $draw_alerts,
$avg_only, false, $date, false, $urlImage,
'adapter_' . $graph_type, $time_compare,
$unknown_graph);
$unknown_graph, true, $fullscale);
echo '<br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height,
@ -226,7 +227,7 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
'adapter_' . $graph_type, $time_compare,
$unknown_graph, true, 'white',
(($show_percentil)? $config['percentil'] : null),
false, false, $config['type_module_charts']);
false, false, $config['type_module_charts'], $fullscale);
echo '<br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height,
@ -399,6 +400,12 @@ $alias = db_get_value ("alias","tagente","id_agente",$id_agent);
break;
}
$data = array();
$data[0] = __('Show full scale graph (TIP)');
$data[1] = html_print_checkbox ("fullscale", 1, (bool) $fullscale, true);
$table->data[] = $data;
$table->rowclass[] = '';
$form_table = html_print_table($table, true);
unset($table);