From edac0d409e53e9194ca6f13e633fb79166b44388 Mon Sep 17 00:00:00 2001 From: ramonn Date: Mon, 2 Aug 2010 12:15:33 +0000 Subject: [PATCH] 2010-08-02 Ramon Novoa * include/functions_reporting.php, include/fgraph.php, include/functions_fsgraph.php, operation/agentes/stat_win.php: Moved min, max and avg information into the chart to make it available to reports an custom graphs. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3084 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 +++ pandora_console/include/fgraph.php | 59 ++++++++----------- pandora_console/include/functions_fsgraph.php | 6 +- .../include/functions_reporting.php | 33 ++++------- .../operation/agentes/stat_win.php | 8 --- 5 files changed, 48 insertions(+), 65 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 7952945367..fb1f437636 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2010-08-02 Ramon Novoa + + * include/functions_reporting.php, include/fgraph.php, + include/functions_fsgraph.php, operation/agentes/stat_win.php: Moved + min, max and avg information into the chart to make it available to + reports an custom graphs. + 2010-08-02 Miguel de Dios * include/functions_filemanager.php: cleaned source code, changed the show to buttons of actions (create file, upload...) to out the list of files. And diff --git a/pandora_console/include/fgraph.php b/pandora_console/include/fgraph.php index 70887ce2c3..db36b3a7f2 100644 --- a/pandora_console/include/fgraph.php +++ b/pandora_console/include/fgraph.php @@ -1367,13 +1367,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $chart = array(); if ($data[0]['utimestamp'] == $datelimit) { $previous_data = $data[0]['datos']; - $min_value = $data[0]['datos']; - $max_value = $data[0]['datos']; $j++; } else { $previous_data = 0; - $min_value = 0; - $max_value = 0; } // Calculate chart data @@ -1406,16 +1402,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, // Data in the interval if ($count > 0) { - - // Avg $total /= $count; - - // Min and max - if ($interval_max > $max_value) { - $max_value = $interval_max; - } else if ($interval_min < $min_value) { - $min_value = $interval_min; - } } // Read events and alerts that fall in the current interval @@ -1457,6 +1444,11 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $chart[$timestamp]['alert'] = $alert_value; } + // Get min, max and avg (less efficient but centralized for all modules and reports) + $min_value = round(get_agentmodule_data_min ($agent_module_id, $period, $date), 2); + $max_value = round(get_agentmodule_data_max ($agent_module_id, $period, $date), 2); + $avg_value = round(get_agentmodule_data_average ($agent_module_id, $period, $date), 2); + // Fix event and alert scale $event_max = $max_value * 1.25; foreach ($chart as $timestamp => $chart_data) { @@ -1491,8 +1483,9 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, } // Flash chart - if (! $graphic_type) { - return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts); + if (! $graphic_type) { + $caption = __('Max. Value') . ': ' . $min_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value; + return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption); } $engine = get_graph_engine ($period); @@ -1609,11 +1602,9 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, $chart = array(); if ($data[0]['utimestamp'] == $datelimit) { $previous_data = $data[0]['datos']; - $max_value = $data[0]['datos']; $j++; } else { $previous_data = 0; - $max_value = 0; } // Calculate chart data @@ -1641,11 +1632,6 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, $total /= $count; } - // Max - if ($total > $max_value) { - $max_value = $total; - } - // Read events and alerts that fall in the current interval $event_value = 0; $alert_value = 0; @@ -1696,7 +1682,12 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, $chart[$timestamp]['event'] = $event_value; $chart[$timestamp]['alert'] = $alert_value; } - + + // Get min, max and avg (less efficient but centralized for all modules and reports) + $min_value = round(get_agentmodule_data_min ($agent_module_id, $period, $date), 2); + $max_value = round(get_agentmodule_data_max ($agent_module_id, $period, $date), 2); + $avg_value = round(get_agentmodule_data_average ($agent_module_id, $period, $date), 2); + // Fix event and alert scale $event_max = $max_value * 1.25; foreach ($chart as $timestamp => $chart_data) { @@ -1731,8 +1722,9 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, } // Flash chart - if (! $graphic_type) { - return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts); + if (! $graphic_type) { + $caption = __('Max. Value') . ': ' . $max_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value; + return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption); } $chart_data = array (); @@ -1869,11 +1861,9 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events, $chart = array(); if ($data[0]['utimestamp'] == $datelimit) { $previous_data = 1; - $max_value = 1; $j++; } else { $previous_data = 0; - $max_value = 0; } // Calculate chart data @@ -1887,11 +1877,6 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events, $j++; } - // Max - if ($count > $max_value) { - $max_value = $count; - } - // Read events and alerts that fall in the current interval $event_value = 0; $alert_value = 0; @@ -1923,6 +1908,11 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events, $chart[$timestamp]['alert'] = $alert_value; } + // Get min, max and avg (less efficient but centralized for all modules and reports) + $min_value = round(get_agentmodule_data_min ($agent_module_id, $period, $date), 2); + $max_value = round(get_agentmodule_data_max ($agent_module_id, $period, $date), 2); + $avg_value = round(get_agentmodule_data_average ($agent_module_id, $period, $date), 2); + // Fix event and alert scale $event_max = $max_value * 1.25; foreach ($chart as $timestamp => $chart_data) { @@ -1957,8 +1947,9 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events, } // Flash chart - if (! $graphic_type) { - return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts); + if (! $graphic_type) { + $caption = __('Max. Value') . ': ' . $min_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value; + return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption); } diff --git a/pandora_console/include/functions_fsgraph.php b/pandora_console/include/functions_fsgraph.php index 42cf654d64..82d58902f2 100644 --- a/pandora_console/include/functions_fsgraph.php +++ b/pandora_console/include/functions_fsgraph.php @@ -131,7 +131,7 @@ function fs_2d_area_chart ($data, $width, $height, $step = 1, $params = '') { } // Returns a Pandora FMS module chart -function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0) { +function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0, $caption = '') { global $config; // Generate the XML @@ -139,6 +139,10 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti $num_vlines = 0; $count = 0; + if ($caption != '') { + $chart->setChartParam("caption", $caption); + } + // Create categories foreach ($data as $value) { if ($count++ % $step == 0) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4977519a3b..c45149d83d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -153,7 +153,6 @@ function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) { // Uncompressed module data if ($uncompressed_module) { - $min_necessary = 1; // Compressed module data } else { @@ -176,22 +175,15 @@ function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } - - $min_necessary = 2; - } - - if (count ($interval_data) < $min_necessary) { - return -1; } // Set initial conditions - $max = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - if ($previous_data['utimestamp'] == $datelimit) { - $max = $previous_data['datos']; - } + if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { + $max = $interval_data[0]['datos']; + } else { + $max = 0; } + foreach ($interval_data as $data) { if ($data['datos'] > $max) { $max = $data['datos']; @@ -255,22 +247,19 @@ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } - - $min_necessary = 2; } - if (count ($interval_data) < $min_necessary) { + if (count ($interval_data) < 1) { return -1; } // Set initial conditions - $min = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - if ($previous_data['utimestamp'] == $datelimit) { - $min = $previous_data['datos']; - } + if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { + $min = $interval_data[0]['datos']; + } else { + $min = 0; } + foreach ($interval_data as $data) { if ($data['datos'] < $min) { $min = $data['datos']; diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 65322e9455..e2bfb076d1 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -166,14 +166,6 @@ else { print_image ($image, false, array ("border" => 0)); } -if ($graph_type != "log4x") { - echo ''; - echo '
'.__('Max. Value').': '.format_for_graph (get_agentmodule_data_max ($id, $period, $date)); - echo ''.__('Avg. Value').': '.format_for_graph (get_agentmodule_data_average ($id, $period, $date)); - echo ''.__('Min. Value').': '.format_for_graph (get_agentmodule_data_min ($id, $period, $date)); - echo '
'; -} - //z-index is 1 because 2 made the calendar show under the divmenu. echo '