fixed errors in TIP SPARSE

This commit is contained in:
daniel 2017-09-20 17:29:17 +02:00
parent 4df624a7c5
commit edb2865430
1 changed files with 489 additions and 429 deletions

View File

@ -570,12 +570,14 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
// Get module data
if ($fullscale) {
$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', true);
fullscale_data( $chart, $chart_data_extra, $long_index, $series_type,
$agent_module_id, $datelimit, $date, $events,
$show_events, $show_unknown, $show_alerts,
$series_suffix, $percentil);
if (count($chart) > $resolution) {
$resolution = count($chart); //Number of points of the graph
$interval = (int) ($period / $resolution);
}
}
else {
$data = db_get_all_rows_filter ('tagente_datos',
@ -619,20 +621,15 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
}
$data = $new_data;
}
}
// Get module warning_min and critical_min
$warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id);
$critical_min = db_get_value('min_critical','tagente_modulo','id_agente_modulo',$agent_module_id);
if ($data === false) {
$data = array ();
}
if ($uncompressed_module) {
// Uncompressed module data
$min_necessary = 1;
}
else {
@ -657,7 +654,6 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$nextData['utimestamp'] = $date;
array_push ($data, $nextData);
}
$min_necessary = 2;
}
@ -674,6 +670,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
graphic_error ();
}
// Data iterator
$data_i = 0;
@ -685,7 +682,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
else {
$previous_data = 0;
}
}
// Get baseline data
$baseline_data = array();
if ($baseline) {
@ -704,40 +701,21 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$unit = modules_get_unit($agent_module_id);
}
if ($fullscale) {
if (count($data) > $resolution) {
$resolution = count($data); //Number of points of the graph
$interval = (int) ($period / $resolution);
}
}
// Get module warning_min and critical_min
$warning_min = db_get_value('min_warning','tagente_modulo','id_agente_modulo',$agent_module_id);
$critical_min = db_get_value('min_critical','tagente_modulo','id_agente_modulo',$agent_module_id);
// Calculate chart data
if($fullscale){
$avg_only = 1;
}
else{
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, $fullscale);
if ($fullscale) {
if (!$flash_chart) {
$time_format = "Y M \nd H:i:s";
}
else {
$time_format = "Y M d H:i:s";
}
$new_chart = array();
$new_long_index = array();
foreach ($chart as $c_timestamp => $c_data) {
$timestamp_short = date($time_format, $c_timestamp);
$new_long_index[$timestamp_short] = date(
html_entity_decode($time_format, ENT_QUOTES, "UTF-8"), $c_timestamp);
$new_chart[$timestamp_short] = $c_data;
}
$long_index = $new_long_index;
$chart = $new_chart;
}
// Return chart data and don't draw
@ -746,7 +724,6 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
}
$graph_stats = get_statwin_graph_statistics($chart, $series_suffix);
// Fix event and alert scale
if ($max_value > 0) {
$event_max = 2 + (float)$max_value * 1.05;
@ -815,7 +792,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
if ($show_events) {
$legend['event'.$series_suffix_str] = __('Events').$series_suffix_str;
$chart_extra_data['legend_events'] = $legend['event'].$series_suffix_str;
$chart_extra_data['legend_events'] = $legend['event'.$series_suffix_str];
}
if ($show_alerts) {
$legend['alert'.$series_suffix] = __('Alerts').$series_suffix_str;
@ -837,11 +814,14 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
__('Last') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['last'], $config['graph_precision'])) . ($unit ? ' ' . $unit : '') . ' ; '
. __('Avg') . ': ' . remove_right_zeros(number_format($graph_stats['sum']['avg'], $config['graph_precision'])) . ($unit ? ' ' . $unit : '');
}
else if (!$avg_only) {
else if (!$avg_only && !$fullscale) {
$legend['max'.$series_suffix] = __('Max').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['max']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['max']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['max']['min'], $config['graph_precision'])).' '.$unit;
$legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('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;
$legend['min'.$series_suffix] = __('Min').$series_suffix_str.': '.__('Avg').': '.remove_right_zeros(number_format($graph_stats['min']['avg'], $config['graph_precision'])).' '.$unit.' ; '.__('Max').': '.remove_right_zeros(number_format($graph_stats['min']['max'], $config['graph_precision'])).' '.$unit.' ; '.__('Min').': '.remove_right_zeros(number_format($graph_stats['min']['min'], $config['graph_precision'])).' '.$unit;
}
else if ($fullscale){
$legend['sum'.$series_suffix] = __('Data').$series_suffix_str.': ';
}
else {
$legend['sum'.$series_suffix] = __('Avg').$series_suffix_str.': '.__('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;
}
@ -933,11 +913,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$date, $unit, $baseline, $return_data, $show_title,
$projection, $adapt_key, $compare, '', '', $show_unknown,
$percentil, $dashboard, $vconsole, $type_graph, $fullscale);
if ($return_data) {
return $data_returned;
}
if ($compare === 'overlapped') {
$i = 0;
foreach ($chart as $k=>$v) {
@ -3850,75 +3828,15 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
if ($fullscale) {
// Get module data
$events = db_get_all_rows_filter('tevento',
array ('id_agentmodule' => $agent_module_id,
"utimestamp > $datelimit",
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('evento', 'utimestamp', 'event_type', 'id_evento'));
$table = "tagente_datos";
$module_type_str = modules_get_type_name ($agent_module_id);
if (strstr ($module_type_str, 'string') !== false) {
$table = "tagente_datos_string";
}
$query = " SELECT utimestamp, datos FROM $table ";
$query .= " WHERE id_agente_modulo=$agent_module_id ";
$query .= " ORDER BY utimestamp ASC LIMIT 1";
$ret = db_get_all_rows_sql( $query , true);
$first_data = $ret[0]['utimestamp'];
/*
// Get the last event after inverval to know if graph start on unknown
$prev_event = db_get_row_filter ('tevento',
array ('id_agentmodule' => $agent_module_id,
"utimestamp <= $datelimit",
'order' => 'utimestamp DESC'));
if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') {
$start_unknown = true;
}
*/
if ($events === false) {
$events = array ();
}
$data_uncompress = db_uncompress_module_data($agent_module_id, $datelimit, $date);
$i = 0;
$data = array();
if(is_array($data_uncompress)){
foreach ($data_uncompress as $value) {
foreach ($value['data'] as $key => $value) {
$data[$i]['datos'] = $value['datos'];
if(empty($value['datos'])){
if($value['utimestamp'] < $first_data){
$data[$i]['unknown'] = 0;
$data[$i]['not_init'] = 1;
$data[$i]['utimestamp'] = $value['utimestamp'];
}
else{
$data[$i]['not_init'] = 0;
$data[$i]['unknown'] = 1;
$data[$i]['utimestamp'] = $value['utimestamp'];
}
}
else{
$data[$i]['not_init'] = 0;
$data[$i]['unknown'] = 0;
}
$data[$i]['utimestamp'] = $value['utimestamp'];
$i++;
}
}
}
if (count($data) > $resolution) {
$resolution = count($data); //Number of points of the graph
fullscale_data( $chart, $chart_data_extra, $long_index, $series_type,
$agent_module_id, $datelimit, $date, $events,
$show_events, $show_unknown, $show_alerts,
$series_suffix);
if (count($chart) > $resolution) {
$resolution = count($chart); //Number of points of the graph
$interval = (int) ($period / $resolution);
}
$max_value=1;
}
else {
// Get module data
@ -3928,7 +3846,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('datos', 'utimestamp'), 'AND', $search_in_history_db);
}
if ($data === false) {
$data = array ();
@ -3972,11 +3890,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
graphic_error ();
}
if (empty($unit_name)) {
$unit = modules_get_unit($agent_module_id);
}
else
$unit = $unit_name;
// Data iterator
$j = 0;
@ -4000,10 +3914,11 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
for ($i = 0; $i <= $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
/*
if ($fullscale && ($resolution > ($config['graph_res'] * 50))) {
$timestamp = $data[$i]['utimestamp'];
}
*/
$zero = 0;
$total = 0;
$count = 0;
@ -4123,10 +4038,6 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
// Data and zeroes (draw a step)
if ($zero == 1 && $count > 0) {
//New code set 0 if there is a 0
//Please check the incident #665
//http://192.168.50.2/integria/index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=665
$chart[$timestamp]['sum'.$series_suffix] = 0;
}
else if ($zero == 1) { // Just zeros
@ -4162,6 +4073,13 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
}
}
if (empty($unit_name)) {
$unit = modules_get_unit($agent_module_id);
}
else
$unit = $unit_name;
// Get min, max and avg (less efficient but centralized for all modules and reports)
$graph_stats = get_statwin_graph_statistics($chart, $series_suffix);
@ -4186,6 +4104,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
///////////////////////////////////////////////////
if(!$fullscale){
// Set the title and time format
if ($period <= SECONDS_6HOURS) {
$time_format = 'H:i:s';
@ -4205,7 +4124,7 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
else {
$time_format = 'M d H\h';
}
}
// Flash chart
$caption = __('Max. Value').$series_suffix_str . ': ' . $graph_stats['sum']['max'] . ' ' . __('Avg. Value').$series_suffix_str .
': ' . $graph_stats['sum']['avg'] . ' ' . __('Min. Value').$series_suffix_str . ': ' . $graph_stats['sum']['min'] . ' ' . __('Units').$series_suffix_str . ': ' . $unit;
@ -4254,6 +4173,167 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
}
}
function fullscale_data ( &$chart_data, &$chart_extra_data, &$long_index,
$series_type, $agent_module_id, $datelimit, $date,
$events = false, $show_events = false,
$show_unknown = false, $show_alerts = false,
$series_suffix = '', $percentil = false ){
global $config;
global $max_value;
global $min_value;
global $series_type;
global $chart_extra_data;
$ranges_unknown = db_get_module_ranges_unknown($agent_module_id, $datelimit, $date);
$table = "tagente_datos";
$module_type_str = modules_get_type_name ($agent_module_id);
if (strstr ($module_type_str, 'string') !== false) {
$table = "tagente_datos_string";
}
$query = " SELECT utimestamp, datos FROM $table ";
$query .= " WHERE id_agente_modulo=$agent_module_id ";
$query .= " ORDER BY utimestamp ASC LIMIT 1";
$ret = db_get_all_rows_sql( $query , true);
$first_data = $ret[0]['utimestamp'];
$data_uncompress = db_uncompress_module_data($agent_module_id, $datelimit, $date);
$i = 0;
$max_value = 0;
$min_value = 0;
$timestamp_second = 0;
if(is_array($data_uncompress)){
foreach ($data_uncompress as $v) {
foreach ($v['data'] as $key => $value) {
$real_date = date("Y M d H:i:s", $value['utimestamp']);
// Read events and alerts that fall in the current interval
$event_value = 0;
$alert_value = 0;
$unknown_value = 0;
$event_i = 0;
// Is the first point of a unknown interval
$first_unknown = false;
$event_ids = array();
$alert_ids = array();
//
if($timestamp_second == 0){
$timestamp_second = $value['utimestamp'];
}
$timestamp_first = $timestamp_second;
$timestamp_second = $value['utimestamp'];
foreach ($events as $key => $val) {
if( $val['utimestamp'] >= $timestamp_first &&
$val['utimestamp'] <= $timestamp_second ){
if ($show_events == 1) {
$event_ids[] = $val['id_evento'];
$event_value++;
}
if ($show_alerts == 1 && substr ($val['event_type'], 0, 5) == 'alert') {
$alert_ids[] = $val['id_evento'];
$alert_value++;
}
if ($show_unknown) {
if ($val['event_type'] == 'going_unknown') {
if ($is_unknown == false) {
$first_unknown = true;
}
$is_unknown = true;
}
else if (substr ($val['event_type'], 0, 5) == 'going') {
$is_unknown = false;
}
}
}
}
if(empty($value['datos'])){
if($value['utimestamp'] < $first_data){
//$chart_data[$real_date]['unknown'.$series_suffix] = 0;
$is_unknown = false;
}
else{
//$chart_data[$real_date]['unknown'.$series_suffix] = 1;
$first_unknown = true;
}
}
$timestamp_short = date("Y M d H:i:s", $value['utimestamp']);
$long_index[$timestamp_short] = date(
html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $value['utimestamp']);
// In some cases, can be marked as known because a recovery event
// was found in same interval. For this cases first_unknown is
// checked too
if ($is_unknown || $first_unknown) {
$unknown_value++;
}
// Data
if ($show_events) {
if (!isset($chart_data[$real_date]['event'.$series_suffix])) {
$chart_data[$real_date]['event'.$series_suffix] = 0;
}
$chart_data[$real_date]['event'.$series_suffix] += $event_value;
$series_type['event'.$series_suffix] = 'points';
}
if ($show_alerts) {
if (!isset($chart_data[$real_date]['alert'.$series_suffix])) {
$chart_data[$real_date]['alert'.$series_suffix] = 0;
}
$chart_data[$real_date]['alert'.$series_suffix] += $alert_value;
$series_type['alert'.$series_suffix] = 'points';
}
$chart_data[$real_date]['sum'.$series_suffix] = $value['datos'];
if($value['datos'] > $max_value){
$max_value = $value['datos'];
}
if($value['datos'] < $min_value){
$min_value = $value['datos'];
}
if ($show_unknown) {
if (!isset($chart_data[$real_date]['unknown'.$series_suffix])) {
$chart_data[$real_date]['unknown'.$series_suffix] = 0;
}
$chart_data[$real_date]['unknown'.$series_suffix] = $unknown_value;
$series_type['unknown'.$series_suffix] = 'area';
}
if (!empty($event_ids)) {
$chart_extra_data[count($chart_data)-1]['events'] = implode(',',$event_ids);
}
if (!empty($alert_ids)) {
$chart_extra_data[count($chart_data)-1]['alerts'] = implode(',',$alert_ids);
}
}
}
if (!is_null($percentil) && $percentil) {
$avg = array_map(function($item) { return $item['sum']; }, $chart_data);
$percentil_result = get_percentile($percentil, $avg);
//Fill the data of chart
array_walk($chart_data, function(&$item) use ($percentil_result, $series_suffix) {
$item['percentil' . $series_suffix] = $percentil_result; });
$series_type['percentil' . $series_suffix] = 'line';
}
}
//html_debug_print($chart_data);
}
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,
@ -4313,26 +4393,6 @@ 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, $fullscale);
if ($fullscale) {
if (!$flash_chart) {
$time_format = "Y M \nd H:i:s";
}
else {
$time_format = "Y M d H:i:s";
}
$new_chart = array();
$new_long_index = array();
foreach ($chart as $c_timestamp => $c_data) {
$timestamp_short = date($time_format, $c_timestamp);
$new_long_index[$timestamp_short] = date(
html_entity_decode($time_format, ENT_QUOTES, "UTF-8"), $c_timestamp);
$new_chart[$timestamp_short] = $c_data;
}
$long_index = $new_long_index;
$chart = $new_chart;
}
if ($compare === 'overlapped') {
$i = 0;