From 0daa808bb8022946c8d7169f4c278113a0048ec9 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 7 Apr 2011 14:34:03 +0000 Subject: [PATCH] 2011-04-07 Miguel de Dios * include/graphs/fgraph.php: changed the img tag to autoclose. * include/graphs/functions_fsgraph.php: changed the border to default 1, and fixed the show legend. * include/functions_graph.php: cleaned source code style. And the function "graphic_combined_module2" added the show timestamp as human, add the min, max, avg values. * include/graphs/functions_pchart.php: changed the show leyend in the top of graph, and added some comments lines for debug. * include/functions_reporting.php, include/functions_custom_graphs.php, godmode/reporting/graph_builder.preview.php: changed the graph to show with new engine. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4177 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 19 ++++ .../reporting/graph_builder.preview.php | 19 +++- .../include/functions_custom_graphs.php | 9 +- pandora_console/include/functions_graph.php | 94 ++++++++++++++++--- .../include/functions_reporting.php | 15 ++- pandora_console/include/graphs/fgraph.php | 2 +- .../include/graphs/functions_fsgraph.php | 16 ++-- .../include/graphs/functions_pchart.php | 92 ++++++++++++++---- 8 files changed, 221 insertions(+), 45 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 460b15be9d..2a02ca3619 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,22 @@ +2011-04-07 Miguel de Dios + + * include/graphs/fgraph.php: changed the img tag to autoclose. + + * include/graphs/functions_fsgraph.php: changed the border to default 1, and + fixed the show legend. + + * include/functions_graph.php: cleaned source code style. And the function + "graphic_combined_module2" added the show timestamp as human, add the + min, max, avg values. + + * include/graphs/functions_pchart.php: changed the show leyend in the top + of graph, and added some comments lines for debug. + + + * include/functions_reporting.php, include/functions_custom_graphs.php, + godmode/reporting/graph_builder.preview.php: changed the graph to show with + new engine. + 2011-04-06 Javier Lanz * pandoradb.sql: Added 'id_group' & 'id_module_group' fields to diff --git a/pandora_console/godmode/reporting/graph_builder.preview.php b/pandora_console/godmode/reporting/graph_builder.preview.php index a3655bb27e..0355e77f62 100644 --- a/pandora_console/godmode/reporting/graph_builder.preview.php +++ b/pandora_console/godmode/reporting/graph_builder.preview.php @@ -141,12 +141,21 @@ echo ""; echo "
"; if(!empty($modules)) { - if ($config['flash_charts']) { - echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $width, $height, + require_once ($config["homedir"] . '/include/functions_graph.php'); + + //if ($config['flash_charts']) { + //echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $width, $height, + // 'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked, $unixdate); + //} + //else { + //echo ""; + //} + + ////////////////////////////////////////////////////////////////////////////// + echo graphic_combined_module2(explode (',', $modules), explode (',', $weights), $period, $width, $height, 'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked, $unixdate); - } else { - echo ""; - } + + /////////////////////////////////////////////////////// } else { echo "
".__('Empty graph')."
"; diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 31283387c5..7164a58fc8 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -92,6 +92,8 @@ function get_user_custom_graphs ($id_user = 0, $only_names = false, $returnAllGr function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $return = false, $date = 0) { global $config; + require_once ($config["homedir"] . '/include/functions_graph.php'); + $sources = get_db_all_rows_field_filter ('tgraph_source', 'id_graph', $id_graph); $modules = array (); $weights = array (); @@ -104,8 +106,12 @@ function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $ret foreach ($sources as $source) { array_push ($modules, $source['id_agent_module']); array_push ($weights, $source['weight']); - } + } + + $output = graphic_combined_module2($modules, $weights, $period, $width, $height, + '', '', 0, 0, 0, $stacked, $date); + /* if ($config['flash_charts']) { $output = graphic_combined_module ($modules, $weights, $period, $width, $height, '', '', 0, 0, 0, $stacked, $date); @@ -114,6 +120,7 @@ function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $ret $weights = implode (',', $weights); $output = ''; } + */ if ($return) return $output; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 16b8792b3f..fe1ae6ef6e 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -255,10 +255,10 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, // Only show caption if graph is not small if ($width > MIN_WIDTH_CAPTION && $height > MIN_HEIGHT) - // Flash chart - $caption = __('Max. Value') . ': ' . $max_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value; + //Flash chart + $caption = __('Max. Value') . ': ' . $max_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value; else - $caption = array(); + $caption = array(); /////// $color = array(); @@ -309,6 +309,29 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, $title, $unit_name, $show_events = 0, $show_alerts = 0, $pure = 0, $stacked = 0, $date = 0) { global $config; global $graphic_type; + + // Set the title and time format + + if ($period <= 3600) { + $title_period = __('Last hour'); + $time_format = 'G:i:s'; + } + elseif ($period <= 86400) { + $title_period = __('Last day'); + $time_format = 'G:i'; + } + elseif ($period <= 604800) { + $title_period = __('Last week'); + $time_format = 'M j'; + } + elseif ($period <= 2419200) { + $title_period = __('Last month'); + $time_format = 'M j'; + } + else { + $title_period = __('Last %s days', format_numeric (($period / (3600 * 24)), 2)); + $time_format = 'M j'; + } // Set variables if ($date == 0) $date = get_system_time(); @@ -332,7 +355,11 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, // Set data containers for ($i = 0; $i < $resolution; $i++) { - $timestamp = $datelimit + ($interval * $i); + $timestamp = $datelimit + ($interval * $i);/* + $timestamp_short = date($time_format, $timestamp); + $long_index[$timestamp_short] = date( + html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); + $timestamp = $timestamp_short;*/ $graph[$timestamp]['count'] = 0; $graph[$timestamp]['timestamp_bottom'] = $timestamp; @@ -343,6 +370,8 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, $graph[$timestamp]['alert'] = 0; } + $long_index = array(); + // Calculate data for each module for ($i = 0; $i < $module_number; $i++) { @@ -432,13 +461,25 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, if ($data[0]['utimestamp'] == $datelimit) { $previous_data = $data[0]['datos']; $j++; - } else { + } + else { $previous_data = 0; } + $max = 0; + $min = null; + $avg = 0; + $countAvg = 0; + // Calculate chart data for ($l = 0; $l < $resolution; $l++) { + $countAvg ++; + $timestamp = $datelimit + ($interval * $l); + $timestamp_short = date($time_format, $timestamp); + $long_index[$timestamp_short] = date( + html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp); + //$timestamp = $timestamp_short; $total = 0; $count = 0; @@ -478,33 +519,56 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, // Data if ($count > 0) { //$graph_values[$i][$timestamp] = $total * $weight_list[$i]; - $temp_graph_values[$timestamp] = $total * $weight_list[$i]; + $temp_graph_values[$timestamp_short] = $total * $weight_list[$i]; $previous_data = $total; // Compressed data } else { if ($uncompressed_module || ($timestamp > time ())) { //$graph_values[$i][$timestamp] = 0; - $temp_graph_values[$timestamp] = 0; + $temp_graph_values[$timestamp_short] = 0; } else { //$graph_values[$i][$timestamp] = $previous_data * $weight_list[$i]; - $temp_graph_values[$timestamp] = $previous_data * $weight_list[$i]; + $temp_graph_values[$timestamp_short] = $previous_data * $weight_list[$i]; } } + //Extract max, min, avg + if ($max < $temp_graph_values[$timestamp_short]) { + $max = $temp_graph_values[$timestamp_short]; + } + + if (isset($min)) { + if ($min > $temp_graph_values[$timestamp_short]) { + $min = $temp_graph_values[$timestamp_short]; + } + } + else { + $min = $temp_graph_values[$timestamp_short]; + } + $avg += $temp_graph_values[$timestamp_short]; + $graph_values[$i] = $temp_graph_values; } + //Add the max, min and avg in the legend + $avg = round($avg / $countAvg, 1); + $module_name_list[$i] .= " (".__("Max"). ":$max, ".__("Min"). ":$min, ". __("Avg"). ": $avg)"; + if ($weight_list[$i] != 1) { + //$module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")"; $module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")"; } - $graph_values[$module_name_list[$i]] = $graph_values[$i]; - unset($graph_values[$i]); + //$graph_values[$module_name_list[$i]] = $graph_values[$i]; + //unset($graph_values[$i]); + + //$graph_values[$i] = $graph_values[$i]; + } - $temp = array(); //debugPrint($graph_values); + $temp = array(); foreach ($graph_values as $graph_group => $point) { foreach ($point as $timestamp_point => $point_value) { $temp[$timestamp_point][$graph_group] = $point_value; @@ -539,8 +603,14 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, //////////////////////////////////////////////////////////////////////////// switch ($stacked) { case 0: + /*$color = array( + 0 => array('alpha' => 50), + 1 => array('alpha' => 50), + 2 => array('alpha' => 50) + );*/ + $color = null; return area_graph($config['flash_charts'], $graph_values, $width, $height, - array(), $module_name_list, array()); + $color, $module_name_list, $long_index); return; break; default: diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index e633fb9974..a744d979eb 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1898,7 +1898,20 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $table->colspan[1][0] = 3; $data = array (); - $data[0] = ''; + //$data[0] = ''; + require_once ($config["homedir"] . '/include/functions_graph.php'); + $data[0] = graphic_combined_module2( + $modules, + $weights, + $content['period'], + $sizgraph_w, $sizgraph_h, + 'Combined%20Sample%20Graph', + '', + 0, + 0, + 0, + $graph["stacked"], + $report["datetime"]); array_push ($table->data, $data); break; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 30579cc344..c86a57384d 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -59,7 +59,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend, serialize_in_temp($graph, $id_graph); - return ""; + return ""; } } diff --git a/pandora_console/include/graphs/functions_fsgraph.php b/pandora_console/include/graphs/functions_fsgraph.php index 85fc4f84ef..f390310c7c 100755 --- a/pandora_console/include/graphs/functions_fsgraph.php +++ b/pandora_console/include/graphs/functions_fsgraph.php @@ -91,17 +91,17 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde $a = 0; $empty = 1; - foreach ($data as $i => $value) { + foreach ($data as $i => $value) { - $legend = ''; + $legend_text = ''; if (isset($legend[$i])) { - $legend = $legend[$i]; + $legend_text = $legend[$i]; } $alpha = ''; $areaBorderColor = ''; $color = ''; - $showAreaBorder = 0; + $showAreaBorder = 1; //0 old default if (isset($color[$i])) { if (!isset($color[$i]['border'])) { $showAreaBorder = 1; @@ -120,14 +120,14 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde } } - $chart->addDataSet($legend, $alpha . + $chart->addDataSet($legend_text, $alpha . 'showAreaBorder=' . $showAreaBorder . ';' . $areaBorderColor . $color); - $count = 0; - $step = 10; - $num_vlines = 0; + $count = 0; + $step = 10; + $num_vlines = 0; foreach ($value as $i2 => $v) { if ($count++ % $step == 0) { diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 4d33661673..0aba9bc0c6 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -45,6 +45,8 @@ if ($id_graph) { $height = $graph['height']; $colors = $graph['color']; $legend = $graph['legend']; + + //debugPrint($graph, true); /* $colors = array(); $colors['pep1'] = array('border' => '#000000', 'color' => '#000000', 'alpha' => 50); @@ -53,6 +55,10 @@ if ($id_graph) { $colors['pep4'] = array('border' => '#000000', 'color' => '#0000ff', 'alpha' => 50); */ $rgb_color = array(); + + if (!isset($colors)) + $colors = array(); + foreach($colors as $i => $color) { $rgb['border'] = html2rgb($color['border']); $rgb_color[$i]['border']['R'] = $rgb['border'][0]; @@ -66,6 +72,26 @@ if ($id_graph) { $rgb_color[$i]['alpha'] = $color['alpha']; } + + /*foreach($colors as $i => $color) { + if (isset($color['border'])) { + $rgb['border'] = html2rgb($color['border']); + $rgb_color[$i]['border']['R'] = $rgb['border'][0]; + $rgb_color[$i]['border']['G'] = $rgb['border'][1]; + $rgb_color[$i]['border']['B'] = $rgb['border'][2]; + } + + if (isset($color['color'])) { + $rgb['color'] = html2rgb($color['color']); + $rgb_color[$i]['color']['R'] = $rgb['color'][0]; + $rgb_color[$i]['color']['G'] = $rgb['color'][1]; + $rgb_color[$i]['color']['B'] = $rgb['color'][2]; + } + + if (isset($color['color'])) { + $rgb_color[$i]['alpha'] = $color['alpha']; + } + }*/ } } @@ -331,22 +357,41 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c $MyData->addPoints($values,$point_id); if (!empty($rgb_color)) { $MyData->setPalette($point_id, - array("R" => $rgb_color[$i]['color']["R"], - "G" => $rgb_color[$i]['color']["G"], - "B" => $rgb_color[$i]['color']["B"], - "BorderR" => $rgb_color[$i]['border']["R"], - "BorderG" => $rgb_color[$i]['border']["G"], - "BorderB" => $rgb_color[$i]['border']["B"], - "Alpha" => $rgb_color[$i]['alpha'])); + array("R" => $rgb_color[$i]['color']["R"], + "G" => $rgb_color[$i]['color']["G"], + "B" => $rgb_color[$i]['color']["B"], + "BorderR" => $rgb_color[$i]['border']["R"], + "BorderG" => $rgb_color[$i]['border']["G"], + "BorderB" => $rgb_color[$i]['border']["B"], + "Alpha" => $rgb_color[$i]['alpha'])); + + /*$palette_color = array(); + if (isset($rgb_color[$i]['color'])) { + $palette_color["R"] = $rgb_color[$i]['color']["R"]; + $palette_color["G"] = $rgb_color[$i]['color']["G"]; + $palette_color["B"] = $rgb_color[$i]['color']["B"]; + } + if (isset($rgb_color[$i]['color'])) { + $palette_color["BorderR"] = $rgb_color[$i]['border']["R"]; + $palette_color["BorderG"] = $rgb_color[$i]['border']["G"]; + $palette_color["BorderB"] = $rgb_color[$i]['border']["B"]; + } + if (isset($rgb_color[$i]['color'])) { + $palette_color["Alpha"] = $rgb_color[$i]['Alpha']; + } + + $MyData->setPalette($point_id, $palette_color);*/ } } - + //$MyData->addPoints($data,"Yaxis"); $MyData->setAxisName(0,$yaxisname); $MyData->addPoints($index,"Xaxis"); $MyData->setSerieDescription("Xaxis", $xaxisname); $MyData->setAbscissa("Xaxis"); + + /* Create the pChart object */ $myPicture = new pImage($width,$height,$MyData); @@ -357,25 +402,38 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0)); /* Set the default font */ - $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>7)); + $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>10)); - /* Define the chart area */ - $myPicture->setGraphArea(30,20,$width,$height-100); + if(isset($legend)) { + /* Write the chart legend */ + $size = $myPicture->getLegendSize(array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL)); + $myPicture->drawLegend($width-$size['Width'], 8,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL)); + } + + if (isset($size['Height'])) { + /* Define the chart area */ + $myPicture->setGraphArea(30,$size['Height'],$width,$height - 60); + } + else { + /* Define the chart area */ + $myPicture->setGraphArea(30, 5,$width,$height - 60); + } /* Draw the scale */ - $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => 40, "LabelRotation" => 90); + $scaleSettings = array("GridR"=>200, + "GridG"=>200, + "GridB"=>200, + "DrawSubTicks"=>TRUE, + "CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "LabelRotation" => 60); $myPicture->drawScale($scaleSettings); - if(isset($legend)) { - /* Write the chart legend */ - $myPicture->drawLegend($height/2,$height-20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); - } + /* Turn on shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); /* Draw the chart */ - $settings = array("ForceTransparency"=>"-1", + $settings = array("ForceTransparency"=>"50", // "Gradient"=>TRUE, "GradientMode"=>GRADIENT_EFFECT_CAN, "DisplayValues"=>$show_values,