Added percentile 95º in the stat win of module. TICKET: #2613

This commit is contained in:
mdtrooper 2015-08-20 17:55:10 +02:00
parent 5bd2a74910
commit 63498fdbf7
8 changed files with 170 additions and 74 deletions

4
pandora_console/include/constants.php Executable file → Normal file
View File

@ -435,4 +435,8 @@ define("PAGINATION_BLOCKS_LIMIT", 15);
/* CHARTS */ /* CHARTS */
define("CHART_DEFAULT_WIDTH", 150); define("CHART_DEFAULT_WIDTH", 150);
define("CHART_DEFAULT_HEIGHT", 110); define("CHART_DEFAULT_HEIGHT", 110);
/* Statwin */
define("STATWIN_DEFAULT_CHART_WIDTH", 555);
define("STATWIN_DEFAULT_CHART_HEIGHT", 245);
?> ?>

View File

@ -2471,4 +2471,18 @@ function extract_column ($array, $column) {
}, $array); }, $array);
} }
function get_percentile($percentile, $array) {
sort($array);
$index = ($percentile / 100) * count($array);
if (floor($index) == $index) {
$result = ($array[$index-1] + $array[$index]) / 2;
}
else {
$result = $array[floor($index)];
}
return $result;
}
?> ?>

78
pandora_console/include/functions_graph.php Executable file → Normal file
View File

@ -230,7 +230,8 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit, $data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit,
$projection, $avg_only = false, $uncompressed_module = false, $projection, $avg_only = false, $uncompressed_module = false,
$show_events = false, $show_alerts = false, $show_unknown = false, $baseline = false, $show_events = false, $show_alerts = false, $show_unknown = false, $baseline = false,
$baseline_data = array(), $events = array(), $series_suffix = '', $start_unknown = false) { $baseline_data = array(), $events = array(), $series_suffix = '', $start_unknown = false,
$percentil = null) {
global $config; global $config;
global $chart_extra_data; global $chart_extra_data;
@ -460,6 +461,18 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i
$chart_extra_data[count($chart)-1]['alerts'] = implode(',',$alert_ids); $chart_extra_data[count($chart)-1]['alerts'] = implode(',',$alert_ids);
} }
} }
if (!is_null($percentil)) {
$avg = array_map(function($item) { return $item['sum'];}, $chart);
$percentil_result = get_percentile($percentil, $avg);
//Fill the data of chart
array_walk($chart, function(&$item) use ($percentil_result, $series_suffix) {
$item['percentil' . $series_suffix] = $percentil_result; });
$series_type['percentil' . $series_suffix] = 'line';
}
} }
@ -468,7 +481,7 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$show_alerts = false, $avg_only = 0, $date = 0, $unit = '', $show_alerts = false, $avg_only = 0, $date = 0, $unit = '',
$baseline = 0, $return_data = 0, $show_title = true, $projection = false, $baseline = 0, $return_data = 0, $show_title = true, $projection = false,
$adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '', $adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '',
$show_unknown = false) { $show_unknown = false, $percentil = null) {
global $config; global $config;
global $chart; global $chart;
@ -550,13 +563,15 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$data = array (); $data = array ();
} }
// Uncompressed module data
if ($uncompressed_module) {
$min_necessary = 1;
// Compressed module data if ($uncompressed_module) {
// Uncompressed module data
$min_necessary = 1;
} }
else { else {
// Compressed module data
// Get previous data // Get previous data
$previous_data = modules_get_previous_data ($agent_module_id, $datelimit); $previous_data = modules_get_previous_data ($agent_module_id, $datelimit);
if ($previous_data !== false) { if ($previous_data !== false) {
@ -626,7 +641,10 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit, $data, $data_i, $previous_data, $resolution, $interval, $period, $datelimit,
$projection, $avg_only, $uncompressed_module, $projection, $avg_only, $uncompressed_module,
$show_events, $show_alerts, $show_unknown, $baseline, $show_events, $show_alerts, $show_unknown, $baseline,
$baseline_data, $events, $series_suffix, $start_unknown); $baseline_data, $events, $series_suffix, $start_unknown,
$percentil);
// Return chart data and don't draw // Return chart data and don't draw
if ($return_data == 1) { if ($return_data == 1) {
@ -647,34 +665,41 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
} }
foreach ($chart as $timestamp => $chart_data) { foreach ($chart as $timestamp => $chart_data) {
if ($show_events && $chart_data['event'.$series_suffix] > 0) { if ($show_events && $chart_data['event' . $series_suffix] > 0) {
$chart[$timestamp]['event'.$series_suffix] = $event_max * 1.2; $chart[$timestamp]['event' . $series_suffix] = $event_max * 1.2;
} }
if ($show_alerts && $chart_data['alert'.$series_suffix] > 0) { if ($show_alerts && $chart_data['alert' . $series_suffix] > 0) {
$chart[$timestamp]['alert'.$series_suffix] = $event_max * 1.10; $chart[$timestamp]['alert' . $series_suffix] = $event_max * 1.10;
} }
if ($show_unknown && $chart_data['unknown'.$series_suffix] > 0) { if ($show_unknown && $chart_data['unknown' . $series_suffix] > 0) {
$chart[$timestamp]['unknown'.$series_suffix] = $event_max * 1.05; $chart[$timestamp]['unknown' . $series_suffix] = $event_max * 1.05;
} }
} }
// Only show caption if graph is not small // Only show caption if graph is not small
if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT) if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT)
//Flash chart //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. Value').$series_suffix_str . ': ' . $unit; $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. Value') . $series_suffix_str . ': ' . $unit;
else else
$caption = array(); $caption = array();
/////// ///////
// Color commented not to restrict serie colors // Color commented not to restrict serie colors
if ($show_events) { if ($show_events) {
$color['event'.$series_suffix] = array('border' => '#ff0000', 'color' => '#ff0000', 'alpha' => 50); $color['event' . $series_suffix] =
array('border' => '#ff0000', 'color' => '#ff0000', 'alpha' => 50);
} }
if ($show_alerts) { if ($show_alerts) {
$color['alert'.$series_suffix] = array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50); $color['alert' . $series_suffix] =
array('border' => '#ff7f00', 'color' => '#ff7f00', 'alpha' => 50);
} }
if ($show_unknown) { if ($show_unknown) {
$color['unknown'.$series_suffix] = array('border' => '#999999', 'color' => '#999999', 'alpha' => 50); $color['unknown' . $series_suffix] =
array('border' => '#999999', 'color' => '#999999', 'alpha' => 50);
} }
$color['max'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 50); $color['max'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color3'], 'alpha' => 50);
$color['sum'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 50); $color['sum'.$series_suffix] = array('border' => '#000000', 'color' => $config['graph_color2'], 'alpha' => 50);
@ -708,6 +733,14 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events,
$legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str; $legend['unknown'.$series_suffix] = __('Unknown').$series_suffix_str;
$chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix_str]; $chart_extra_data['legend_unknown'] = $legend['unknown'.$series_suffix_str];
} }
if (!is_null($percentil)) {
$first_data = reset($chart);
$percentil_value = format_for_graph($first_data['percentil'], 2);
$legend['percentil'.$series_suffix] = __('Percentile %dº', $percentil) .$series_suffix_str . " (" . $percentil_value . " " . $unit . ") ";
$chart_extra_data['legend_percentil'] = $legend['percentil'.$series_suffix_str];
}
} }
function grafico_modulo_sparse ($agent_module_id, $period, $show_events, function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
@ -716,7 +749,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$unit = '', $baseline = 0, $return_data = 0, $show_title = true, $unit = '', $baseline = 0, $return_data = 0, $show_title = true,
$only_image = false, $homeurl = '', $ttl = 1, $projection = false, $only_image = false, $homeurl = '', $ttl = 1, $projection = false,
$adapt_key = '', $compare = false, $show_unknown = false, $adapt_key = '', $compare = false, $show_unknown = false,
$menu = true, $backgroundColor = 'white') { $menu = true, $backgroundColor = 'white', $percentil = null) {
global $config; global $config;
global $graphic_type; global $graphic_type;
@ -747,7 +780,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$show_alerts, $avg_only, $date-$period, $unit, $baseline, $show_alerts, $avg_only, $date-$period, $unit, $baseline,
$return_data, $show_title, $projection, $adapt_key, $return_data, $show_title, $projection, $adapt_key,
$compare, $series_suffix, $series_suffix_str, $compare, $series_suffix, $series_suffix_str,
$show_unknown); $show_unknown, $percentil);
switch ($compare) { switch ($compare) {
case 'separated': case 'separated':
@ -773,13 +808,16 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
} }
} }
// Build the data of the current period // Build the data of the current period
$data_returned = grafico_modulo_sparse_data ($agent_module_id, $data_returned = grafico_modulo_sparse_data ($agent_module_id,
$period, $show_events, $period, $show_events,
$width, $height , $title, $unit_name, $width, $height , $title, $unit_name,
$show_alerts, $avg_only, $show_alerts, $avg_only,
$date, $unit, $baseline, $return_data, $show_title, $date, $unit, $baseline, $return_data, $show_title,
$projection, $adapt_key, $compare, '', '', $show_unknown); $projection, $adapt_key, $compare, '', '', $show_unknown,
$percentil);
if ($return_data) { if ($return_data) {
return $data_returned; return $data_returned;

1
pandora_console/include/graphs/fgraph.php Executable file → Normal file
View File

@ -214,6 +214,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,
$red_threshold = 0, $adapt_key = '', $force_integer = false, $red_threshold = 0, $adapt_key = '', $force_integer = false,
$series_suffix_str = '', $menu = true, $backgroundColor = 'white') { $series_suffix_str = '', $menu = true, $backgroundColor = 'white') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url); setup_watermark($water_mark, $water_mark_file, $water_mark_url);
// ATTENTION: The min size is in constants.php // ATTENTION: The min size is in constants.php

View File

@ -606,11 +606,17 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
} }
}); });
switch(serie_types[i]) { switch (serie_types[i]) {
case 'area':
line_show = true;
points_show = false;
filled = true;
break;
case 'line': case 'line':
default: default:
line_show = true; line_show = true;
points_show = false; points_show = false;
filled = false;
break; break;
case 'points': case 'points':
line_show = false; line_show = false;

View File

@ -161,6 +161,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
global $config; global $config;
include_javascript_dependencies_flot_graph(); include_javascript_dependencies_flot_graph();
$font_size = '7'; $font_size = '7';
@ -269,13 +270,25 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
foreach($values as $key => $value) { foreach($values as $key => $value) {
$jsvar = "data_" . $graph_id . "_" . $key; $jsvar = "data_" . $graph_id . "_" . $key;
if (!isset($serie_types[$key])) { if (!isset($serie_types[$key])) {
switch ($type) {
case 'line_simple':
case 'line_stacked':
$serie_types2[$jsvar] = 'line'; $serie_types2[$jsvar] = 'line';
break;
case 'area_simple':
case 'area_stacked':
default:
$serie_types2[$jsvar] = 'area';
break;
}
} }
else { else {
$serie_types2[$jsvar] = $serie_types[$key]; $serie_types2[$jsvar] = $serie_types[$key];
} }
if ($serie_types2[$jsvar] == 'points' && $value == 0) { if ($serie_types2[$jsvar] == 'points' && $value == 0) {
$data[$jsvar][] = 'null'; $data[$jsvar][] = 'null';
} }
@ -384,32 +397,32 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
$return .= "<script type='text/javascript'>"; $return .= "<script type='text/javascript'>";
$return .= "//<![CDATA[\n"; $return .= "//<![CDATA[\n";
$return .= "pandoraFlotArea(" . $return .= "pandoraFlotArea(" .
"'$graph_id', " . "'$graph_id', \n" .
"'$values', " . "'$values', \n" .
"'$labels', " . "'$labels', \n" .
"'$labels_long', " . "'$labels_long', \n" .
"'$legend', " . "'$legend', \n" .
"'$colors', " . "'$colors', \n" .
"'$type', " . "'$type', \n" .
"'$serie_types', " . "'$serie_types', \n" .
"$watermark, " . "$watermark, \n" .
"$width, " . "$width, \n" .
"$max_x, " . "$max_x, \n" .
"'" . $homeurl . "', " . "'" . $homeurl . "', \n" .
"'$unit', " . "'$unit', \n" .
"$font_size, " . "$font_size, \n" .
"$menu, " . "$menu, \n" .
"'$events', " . "'$events', \n" .
"'$event_ids', " . "'$event_ids', \n" .
"'$legend_events', " . "'$legend_events', \n" .
"'$alerts', " . "'$alerts', \n" .
"'$alert_ids', " . "'$alert_ids', \n" .
"'$legend_alerts', " . "'$legend_alerts', \n" .
"'$yellow_threshold', " . "'$yellow_threshold', \n" .
"'$red_threshold', " . "'$red_threshold', \n" .
"$force_integer, " . "$force_integer, \n" .
"'$separator', " . "'$separator', \n" .
"'$separator2', " . "'$separator2', \n" .
"'$series_suffix_str');"; "'$series_suffix_str');";
$return .= "\n//]]>"; $return .= "\n//]]>";
$return .= "</script>"; $return .= "</script>";

0
pandora_console/include/graphs/functions_pchart.php Executable file → Normal file
View File

View File

@ -116,7 +116,8 @@ $id = get_parameter('id');
// ACL // ACL
$permission = false; $permission = false;
$agent_group = (int) agents_get_agent_group($agent_id); $agent_group = (int) agents_get_agent_group($agent_id);
$strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); $strict_user = (bool) db_get_value("strict_acl", "tusuario",
"id_user", $config['id_user']);
if (!empty($agent_group)) { if (!empty($agent_group)) {
if ($strict_user) { if ($strict_user) {
@ -140,8 +141,8 @@ $id = get_parameter('id');
} }
$period = get_parameter ("period", SECONDS_1DAY); $period = get_parameter ("period", SECONDS_1DAY);
$id = get_parameter ("id", 0); $id = get_parameter ("id", 0);
$width = get_parameter ("width", 555); $width = get_parameter ("width", STATWIN_DEFAULT_CHART_WIDTH);
$height = get_parameter ("height", 245); $height = get_parameter ("height", STATWIN_DEFAULT_CHART_HEIGHT);
$label = get_parameter ("label", ""); $label = get_parameter ("label", "");
$start_date = get_parameter ("start_date", date("Y/m/d")); $start_date = get_parameter ("start_date", date("Y/m/d"));
$start_time = get_parameter ("start_time", date("H:i:s")); $start_time = get_parameter ("start_time", date("H:i:s"));
@ -150,6 +151,7 @@ $id = get_parameter('id');
$zoom = get_parameter ("zoom", 1); $zoom = get_parameter ("zoom", 1);
$baseline = get_parameter ("baseline", 0); $baseline = get_parameter ("baseline", 0);
$show_events_graph = get_parameter ("show_events_graph", 0); $show_events_graph = get_parameter ("show_events_graph", 0);
$show_percentil_95 = get_parameter ("show_percentil_95", 0);
$time_compare_separated = get_parameter ("time_compare_separated", 0); $time_compare_separated = get_parameter ("time_compare_separated", 0);
$time_compare_overlapped = get_parameter ("time_compare_overlapped", 0); $time_compare_overlapped = get_parameter ("time_compare_overlapped", 0);
$unknown_graph = get_parameter_checkbox ("unknown_graph", 1); $unknown_graph = get_parameter_checkbox ("unknown_graph", 1);
@ -190,33 +192,46 @@ $id = get_parameter('id');
switch ($graph_type) { switch ($graph_type) {
case 'boolean': case 'boolean':
echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height, echo grafico_modulo_boolean ($id, $period, $draw_events,
$label, $unit, $draw_alerts, $avg_only, false, $date, false, $urlImage, 'adapter_'.$graph_type, $time_compare, $unknown_graph); $width, $height, $label, $unit, $draw_alerts,
$avg_only, false, $date, false, $urlImage,
'adapter_' . $graph_type, $time_compare,
$unknown_graph);
echo '<br>'; echo '<br>';
if ($show_events_graph) if ($show_events_graph)
echo graphic_module_events($id, $width, $height, echo graphic_module_events($id, $width, $height,
$period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); $period, $config['homeurl'], $zoom,
'adapted_' . $graph_type, $date);
break; break;
case 'sparse': case 'sparse':
echo grafico_modulo_sparse ($id, $period, $draw_events, $width, $height, echo grafico_modulo_sparse ($id, $period, $draw_events,
$label, $unit, $draw_alerts, $avg_only, false, $date, $unit, $baseline, $width, $height, $label, $unit, $draw_alerts,
0, true, false, $urlImage, 1, false, 'adapter_'.$graph_type, $time_compare, $unknown_graph); $avg_only, false, $date, $unit, $baseline, 0, true,
false, $urlImage, 1, false,
'adapter_' . $graph_type, $time_compare,
$unknown_graph, true, 'white',
(($show_percentil_95)? 95 : null));
echo '<br>'; echo '<br>';
if ($show_events_graph) if ($show_events_graph)
echo graphic_module_events($id, $width, $height, echo graphic_module_events($id, $width, $height,
$period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); $period, $config['homeurl'], $zoom,
'adapted_' . $graph_type, $date);
break; break;
case 'string': case 'string':
echo grafico_modulo_string ($id, $period, $draw_events, $width, $height, echo grafico_modulo_string ($id, $period, $draw_events,
$label, null, $draw_alerts, 1, false, $date, false, $urlImage, 'adapter_'.$graph_type); $width, $height, $label, null, $draw_alerts, 1,
false, $date, false, $urlImage,
'adapter_' . $graph_type);
echo '<br>'; echo '<br>';
if ($show_events_graph) if ($show_events_graph)
echo graphic_module_events($id, $width, $height, echo graphic_module_events($id, $width, $height,
$period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); $period, $config['homeurl'], $zoom,
'adapted_' . $graph_type, $date);
break; break;
case 'log4x': case 'log4x':
echo grafico_modulo_log4x ($id, $period, $draw_events, $width, $height, echo grafico_modulo_log4x ($id, $period, $draw_events,
$label, $unit, $draw_alerts, 1, $pure, $date); $width, $height, $label, $unit, $draw_alerts, 1,
$pure, $date);
echo '<br>'; echo '<br>';
if ($show_events_graph) if ($show_events_graph)
echo graphic_module_events($id, $width, $height, echo graphic_module_events($id, $width, $height,
@ -339,10 +354,15 @@ $id = get_parameter('id');
$table->data[] = $data; $table->data[] = $data;
$table->rowclass[] = ''; $table->rowclass[] = '';
switch ($graph_type) { switch ($graph_type) {
case 'boolean': case 'boolean':
case 'sparse': case 'sparse':
$data = array();
$data[0] = __('Show percentil 95º');
$data[1] = html_print_checkbox ("show_percentil_95", 1, (bool) $show_percentil_95, true);
$table->data[] = $data;
$table->rowclass[] ='';
$data = array(); $data = array();
$data[0] = __('Time compare (Overlapped)'); $data[0] = __('Time compare (Overlapped)');
$data[1] = html_print_checkbox ("time_compare_overlapped", 1, (bool) $time_compare_overlapped, true); $data[1] = html_print_checkbox ("time_compare_overlapped", 1, (bool) $time_compare_overlapped, true);