From 63498fdbf7b053241b12935f123656fe435b3a76 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 20 Aug 2015 17:55:10 +0200 Subject: [PATCH] =?UTF-8?q?Added=20percentile=2095=C2=BA=20in=20the=20stat?= =?UTF-8?q?=20win=20of=20module.=20TICKET:=20#2613?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pandora_console/include/constants.php | 4 + pandora_console/include/functions.php | 16 +++- pandora_console/include/functions_graph.php | 82 ++++++++++++++----- pandora_console/include/graphs/fgraph.php | 1 + .../include/graphs/flot/pandora.flot.js | 16 ++-- .../include/graphs/functions_flot.php | 67 +++++++++------ .../include/graphs/functions_pchart.php | 6 +- .../operation/agentes/stat_win.php | 52 ++++++++---- 8 files changed, 170 insertions(+), 74 deletions(-) mode change 100755 => 100644 pandora_console/include/constants.php mode change 100755 => 100644 pandora_console/include/functions_graph.php mode change 100755 => 100644 pandora_console/include/graphs/fgraph.php mode change 100755 => 100644 pandora_console/include/graphs/functions_pchart.php diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php old mode 100755 new mode 100644 index fc5a6025b2..d4b74374c9 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -435,4 +435,8 @@ define("PAGINATION_BLOCKS_LIMIT", 15); /* CHARTS */ define("CHART_DEFAULT_WIDTH", 150); define("CHART_DEFAULT_HEIGHT", 110); + +/* Statwin */ +define("STATWIN_DEFAULT_CHART_WIDTH", 555); +define("STATWIN_DEFAULT_CHART_HEIGHT", 245); ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index e92a6a7c5d..a42b94ddb2 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -2471,4 +2471,18 @@ function extract_column ($array, $column) { }, $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; +} +?> \ No newline at end of file diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php old mode 100755 new mode 100644 index 87a2c7804a..8d8581c412 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -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, $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) { + $baseline_data = array(), $events = array(), $series_suffix = '', $start_unknown = false, + $percentil = null) { global $config; global $chart_extra_data; @@ -241,10 +242,10 @@ function grafico_modulo_sparse_data_chart (&$chart, &$chart_data_extra, &$long_i $max_value = 0; $min_value = null; $flash_chart = $config['flash_charts']; - + // Event iterator $event_i = 0; - + // Is unknown flag $is_unknown = $start_unknown; @@ -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); } } + + + 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 = '', $baseline = 0, $return_data = 0, $show_title = true, $projection = false, $adapt_key = '', $compare = false, $series_suffix = '', $series_suffix_str = '', - $show_unknown = false) { + $show_unknown = false, $percentil = null) { global $config; global $chart; @@ -550,13 +563,15 @@ function grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $data = array (); } - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - // Compressed module data + if ($uncompressed_module) { + // Uncompressed module data + + $min_necessary = 1; } else { + // Compressed module data + // Get previous data $previous_data = modules_get_previous_data ($agent_module_id, $datelimit); 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, $projection, $avg_only, $uncompressed_module, $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 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) { - if ($show_events && $chart_data['event'.$series_suffix] > 0) { - $chart[$timestamp]['event'.$series_suffix] = $event_max * 1.2; + if ($show_events && $chart_data['event' . $series_suffix] > 0) { + $chart[$timestamp]['event' . $series_suffix] = $event_max * 1.2; } - if ($show_alerts && $chart_data['alert'.$series_suffix] > 0) { - $chart[$timestamp]['alert'.$series_suffix] = $event_max * 1.10; + if ($show_alerts && $chart_data['alert' . $series_suffix] > 0) { + $chart[$timestamp]['alert' . $series_suffix] = $event_max * 1.10; } - if ($show_unknown && $chart_data['unknown'.$series_suffix] > 0) { - $chart[$timestamp]['unknown'.$series_suffix] = $event_max * 1.05; + if ($show_unknown && $chart_data['unknown' . $series_suffix] > 0) { + $chart[$timestamp]['unknown' . $series_suffix] = $event_max * 1.05; } } // Only show caption if graph is not small if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT) //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 $caption = array(); /////// // Color commented not to restrict serie colors 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) { - $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) { - $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['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; $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, @@ -716,7 +749,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $unit = '', $baseline = 0, $return_data = 0, $show_title = true, $only_image = false, $homeurl = '', $ttl = 1, $projection = false, $adapt_key = '', $compare = false, $show_unknown = false, - $menu = true, $backgroundColor = 'white') { + $menu = true, $backgroundColor = 'white', $percentil = null) { global $config; 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, $return_data, $show_title, $projection, $adapt_key, $compare, $series_suffix, $series_suffix_str, - $show_unknown); + $show_unknown, $percentil); + + switch ($compare) { case 'separated': @@ -773,13 +808,16 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, } } + // Build the data of the current period $data_returned = grafico_modulo_sparse_data ($agent_module_id, $period, $show_events, $width, $height , $title, $unit_name, $show_alerts, $avg_only, $date, $unit, $baseline, $return_data, $show_title, - $projection, $adapt_key, $compare, '', '', $show_unknown); + $projection, $adapt_key, $compare, '', '', $show_unknown, + $percentil); + if ($return_data) { return $data_returned; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php old mode 100755 new mode 100644 index 6d72d677d0..60e4035543 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -214,6 +214,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $red_threshold = 0, $adapt_key = '', $force_integer = false, $series_suffix_str = '', $menu = true, $backgroundColor = 'white') { + setup_watermark($water_mark, $water_mark_file, $water_mark_url); // ATTENTION: The min size is in constants.php diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 391c62d8f4..25e82aec1a 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -569,11 +569,11 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, }); switch(type) { - case 'line_simple': + case 'line_simple': stacked = null; filled = false; break; - case 'line_stacked': + case 'line_stacked': stacked = 'stack'; filled = false; break; @@ -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': default: line_show = true; points_show = false; + filled = false; break; case 'points': line_show = false; @@ -645,7 +651,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, //~ { color: criticalw, yaxis: { from: vcritical_min } }, //~ { color: criticalw, yaxis: { to: -1 } } //~ ]; - + lineWidht = $('#hidden-lineWidhtGraph'); if (typeof(lineWidht[0])=='undefined'){ WidhtLine = 1; @@ -653,7 +659,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, else{ WidhtLine = lineWidht[0].value; } - + // Data data_base.push({ id: 'serie_' + i, diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index c204ae1f8e..b88f962853 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -161,6 +161,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, global $config; + include_javascript_dependencies_flot_graph(); $font_size = '7'; @@ -269,13 +270,25 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, foreach($values as $key => $value) { $jsvar = "data_" . $graph_id . "_" . $key; + if (!isset($serie_types[$key])) { - $serie_types2[$jsvar] = 'line'; + switch ($type) { + case 'line_simple': + case 'line_stacked': + $serie_types2[$jsvar] = 'line'; + break; + case 'area_simple': + case 'area_stacked': + default: + $serie_types2[$jsvar] = 'area'; + break; + } } else { $serie_types2[$jsvar] = $serie_types[$key]; } + if ($serie_types2[$jsvar] == 'points' && $value == 0) { $data[$jsvar][] = 'null'; } @@ -384,32 +397,32 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $return .= ""; diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php old mode 100755 new mode 100644 index b231d889f1..ba9d839b0f --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -162,7 +162,7 @@ switch($graph_type) { } $data_keys[] = $i; - + } $fine_colors = array(); @@ -686,13 +686,13 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $MyData->setSerieWeight($point_id, 0); } - + //$MyData->addPoints($data,"Yaxis"); $MyData->setAxisName(0,$yaxisname); $MyData->addPoints($index,"Xaxis"); $MyData->setSerieDescription("Xaxis", $xaxisname); $MyData->setAbscissa("Xaxis"); - + switch($backgroundColor) { case 'white': $transparent = false; diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 002616a78c..5e6f57519a 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -116,7 +116,8 @@ $id = get_parameter('id'); // ACL $permission = false; $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 ($strict_user) { @@ -140,8 +141,8 @@ $id = get_parameter('id'); } $period = get_parameter ("period", SECONDS_1DAY); $id = get_parameter ("id", 0); - $width = get_parameter ("width", 555); - $height = get_parameter ("height", 245); + $width = get_parameter ("width", STATWIN_DEFAULT_CHART_WIDTH); + $height = get_parameter ("height", STATWIN_DEFAULT_CHART_HEIGHT); $label = get_parameter ("label", ""); $start_date = get_parameter ("start_date", date("Y/m/d")); $start_time = get_parameter ("start_time", date("H:i:s")); @@ -150,6 +151,7 @@ $id = get_parameter('id'); $zoom = get_parameter ("zoom", 1); $baseline = get_parameter ("baseline", 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_overlapped = get_parameter ("time_compare_overlapped", 0); $unknown_graph = get_parameter_checkbox ("unknown_graph", 1); @@ -190,33 +192,46 @@ $id = get_parameter('id'); switch ($graph_type) { case 'boolean': - echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height, - $label, $unit, $draw_alerts, $avg_only, false, $date, false, $urlImage, 'adapter_'.$graph_type, $time_compare, $unknown_graph); + echo grafico_modulo_boolean ($id, $period, $draw_events, + $width, $height, $label, $unit, $draw_alerts, + $avg_only, false, $date, false, $urlImage, + 'adapter_' . $graph_type, $time_compare, + $unknown_graph); echo '
'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, - $period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); + $period, $config['homeurl'], $zoom, + 'adapted_' . $graph_type, $date); break; case 'sparse': - echo grafico_modulo_sparse ($id, $period, $draw_events, $width, $height, - $label, $unit, $draw_alerts, $avg_only, false, $date, $unit, $baseline, - 0, true, false, $urlImage, 1, false, 'adapter_'.$graph_type, $time_compare, $unknown_graph); + echo grafico_modulo_sparse ($id, $period, $draw_events, + $width, $height, $label, $unit, $draw_alerts, + $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 '
'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, - $period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); + $period, $config['homeurl'], $zoom, + 'adapted_' . $graph_type, $date); break; case 'string': - echo grafico_modulo_string ($id, $period, $draw_events, $width, $height, - $label, null, $draw_alerts, 1, false, $date, false, $urlImage, 'adapter_'.$graph_type); + echo grafico_modulo_string ($id, $period, $draw_events, + $width, $height, $label, null, $draw_alerts, 1, + false, $date, false, $urlImage, + 'adapter_' . $graph_type); echo '
'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, - $period, $config['homeurl'], $zoom, 'adapted_'.$graph_type, $date); + $period, $config['homeurl'], $zoom, + 'adapted_' . $graph_type, $date); break; case 'log4x': - echo grafico_modulo_log4x ($id, $period, $draw_events, $width, $height, - $label, $unit, $draw_alerts, 1, $pure, $date); + echo grafico_modulo_log4x ($id, $period, $draw_events, + $width, $height, $label, $unit, $draw_alerts, 1, + $pure, $date); echo '
'; if ($show_events_graph) echo graphic_module_events($id, $width, $height, @@ -339,10 +354,15 @@ $id = get_parameter('id'); $table->data[] = $data; $table->rowclass[] = ''; - switch ($graph_type) { case 'boolean': 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[0] = __('Time compare (Overlapped)'); $data[1] = html_print_checkbox ("time_compare_overlapped", 1, (bool) $time_compare_overlapped, true);