Merge branch 'feature/ticket#1331-CombinedGraph' into develop

This commit is contained in:
Alejandro Gallardo Escobar 2014-09-23 13:21:47 +02:00
commit 0f99287940
5 changed files with 167 additions and 51 deletions

View File

@ -400,12 +400,33 @@ $table->data[$row][1] = html_print_input_text ('networkmap_max_width', $config["
$row++;
$table->data[$row][0] = __('Fixed header');
$table->data[$row][1] = html_print_checkbox('fixed_header', 1, $config['fixed_header'], true);
$table->data[$row][1] = __('Yes') . ' ' .
html_print_radio_button ('fixed_header', 1, '', $config["fixed_header"], true) .
'  ';
$table->data[$row][1] .= __('No') . ' ' .
html_print_radio_button ('fixed_header', 0, '', $config["fixed_header"], true);
$row++;
$table->data[$row][0] = __('Fixed menu');
$table->data[$row][1] = html_print_checkbox('fixed_menu', 1, $config['fixed_menu'], true);
$table->data[$row][1] = __('Yes') . ' ' .
html_print_radio_button ('fixed_menu', 1, '', $config["fixed_menu"], true) .
'  ';
$table->data[$row][1] .= __('No') . ' ' .
html_print_radio_button ('fixed_menu', 0, '', $config["fixed_menu"], true);
$row++;
if (!isset($config["short_module_graph_data"]))
$config["short_module_graph_data"] = true;
$table->data[$row][0] = __('Shortened module graph data');
$table->data[$row][0] .= ui_print_help_tip(__('The data number of the module graphs will be rounded and shortened'), true);
$table->data[$row][1] = __('Yes') . ' ' .
html_print_radio_button ('short_module_graph_data', 1, '', $config["short_module_graph_data"], true) .
'  ';
$table->data[$row][1] .= __('No') . ' ' .
html_print_radio_button ('short_module_graph_data', 0, '', $config["short_module_graph_data"], true);
$row++;

View File

@ -447,6 +447,8 @@ function config_update_config () {
$error_update[] = __('Custom graphviz directory');
if (!config_update_value ('networkmap_max_width', get_parameter('networkmap_max_width')))
$error_update[] = __('Networkmap max width');
if (!config_update_value ('short_module_graph_data', get_parameter('short_module_graph_data')))
$error_update[] = __('Shortened module graph data');
$interval_values = get_parameter ('interval_values');

View File

@ -145,14 +145,25 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr
* @param $height Height of the returning image.
* @param $width Width of the returning image.
* @param $period Period of time to get data in seconds.
* @param $stacked Wheter the graph is stacked or not.
* @param $stacked Whether the graph is stacked or not.
* @param $return Whether to return an output string or echo now (optional, echo by default).
* @param $date Date to start printing the graph
* @param bool Wether to show an image instead a interactive chart or not
* @param string Background color
* @param array List of names for the items. Should have the same size as the module list.
* @param bool Show the last value of the item on the list.
* @param bool Show the max value of the item on the list.
* @param bool Show the min value of the item on the list.
* @param bool Show the average value of the item on the list.
*
* @return Mixed
*/
function custom_graphs_print($id_graph, $height, $width, $period,
$stacked = null, $return = false, $date = 0, $only_image = false,
$background_color = 'white', $modules_param = array(), $homeurl = '') {
$background_color = 'white', $modules_param = array(), $homeurl = '',
$name_list = array(), $unit_list = array(), $show_last = true,
$show_max = true, $show_min = true, $show_avg = true) {
global $config;
@ -214,7 +225,13 @@ function custom_graphs_print($id_graph, $height, $width, $period,
1,
false,
false,
$background_color);
$background_color,
$name_list,
$unit_list,
$show_last,
$show_max,
$show_min,
$show_avg);
if ($return)
return $output;

View File

@ -854,6 +854,12 @@ function graph_get_formatted_date($timestamp, $format1, $format2) {
* @param int Date to start of getting info.
* @param mixed If is a projection graph this parameter will be module data with prediction data (the projection)
* or false in other case.
* @param array List of names for the items. Should have the same size as the module list.
* @param array List of units for the items. Should have the same size as the module list.
* @param bool Show the last value of the item on the list.
* @param bool Show the max value of the item on the list.
* @param bool Show the min value of the item on the list.
* @param bool Show the average value of the item on the list.
*
* @return Mixed
*/
@ -861,7 +867,9 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$width, $height, $title, $unit_name, $show_events = 0,
$show_alerts = 0, $pure = 0, $stacked = 0, $date = 0,
$only_image = false, $homeurl = '', $ttl = 1, $projection = false,
$prediction_period = false, $background_color = 'white') {
$prediction_period = false, $background_color = 'white',
$name_list = array(), $unit_list = array(), $show_last = true, $show_max = true,
$show_min = true, $show_avg = true) {
global $config;
global $graphic_type;
@ -929,6 +937,9 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$module_number = count ($module_list);
}
$names_number = count($name_list);
$units_number = count($unit_list);
// interval - This is the number of "rows" we are divided the time to fill data.
// more interval, more resolution, and slower.
// periodo - Gap of time, in seconds. This is now to (now-periodo) secs
@ -971,6 +982,10 @@ function graphic_combined_module ($module_list, $weight_list, $period,
if ($projection != false && $i != 0) {
$agent_module_id = $module_list[0];
if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) {
$module_name_list[$i] = $name_list[$i];
}
else {
//Get and process agent name
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($agent_module_id));
@ -986,8 +1001,9 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$module_name = sprintf(__("projection for %s"), $module_name);
$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
$module_name_list[$i] = $agent_name ." / ". $module_name;
}
$id_module_type = modules_get_agentmodule_type ($agent_module_id);
$module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type);
@ -995,6 +1011,10 @@ function graphic_combined_module ($module_list, $weight_list, $period,
else {
$agent_module_id = $module_list[$i];
if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) {
$module_name_list[$i] = $name_list[$i];
}
else {
//Get and process agent name
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($agent_module_id));
@ -1009,6 +1029,8 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
$module_name_list[$i] = $agent_name . " / " . $module_name;
}
$id_module_type = modules_get_agentmodule_type ($agent_module_id);
$module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type);
@ -1199,18 +1221,60 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$graph_stats = get_graph_statistics($graph_values[$i]);
if (!isset($config["short_module_graph_data"]))
$config["short_module_graph_data"] = true;
if ($config["short_module_graph_data"]) {
$min = $graph_stats['min'];
$max = $graph_stats['max'];
$avg = $graph_stats['avg'];
$last = $graph_stats['last'];
$units = modules_get_unit($agent_module_id);
if ($min > 1000000)
$min = sprintf("%sM", number_format($min / 1000000, 2));
else if ($min > 1000)
$min = sprintf("%sK", number_format($min / 1000, 2));
if ($max > 1000000)
$max = sprintf("%sM", number_format($max / 1000000, 2));
else if ($max > 1000)
$max = sprintf("%sK", number_format($max / 1000, 2));
if ($avg > 1000000)
$avg = sprintf("%sM", number_format($avg / 1000000, 2));
else if ($avg > 1000)
$avg = sprintf("%sK", number_format($avg / 1000, 2));
if ($last > 1000000)
$last = sprintf("%sM", number_format($last / 1000000, 2));
else if ($last > 1000)
$last = sprintf("%sK", number_format($last / 1000, 2));
}
else {
$min = number_format($graph_stats['min'], 2);
$max = number_format($graph_stats['max'], 2);
$avg = number_format($graph_stats['avg'], 2);
$last = number_format($graph_stats['last'], 2);
}
if (!empty($unit_list) && $units_number == $module_number && isset($unit_list[$i])) {
$unit = $unit_list[$i];
}
else {
$unit = modules_get_unit($agent_module_id);
}
if ($projection == false or ($projection != false and $i == 0)) {
$module_name_list[$i] .= ": " .
__('Last') . ": $last $units; " .
__("Max") . ": $max $units; " .
__("Min") . ": $min $units; " .
__("Avg") . ": $avg";
$module_name_list[$i] .= ": ";
if ($show_last)
$module_name_list[$i] .= __('Last') . ": $last $unit; ";
if ($show_max)
$module_name_list[$i] .= __("Max") . ": $max $unit; ";
if ($show_min)
$module_name_list[$i] .= __("Min") . ": $min $unit; ";
if ($show_avg)
$module_name_list[$i] .= __("Avg") . ": $avg $unit";
}
if ($weight_list[$i] != 1) {

View File

@ -60,8 +60,8 @@ $params = json_decode($params_json, true);
$interface_name = (string) $params['interface_name'];
$agent_id = (int) $params['agent_id'];
$interface_traffic_modules = array(
'in' => (int) $params['traffic_module_in'],
'out' => (int) $params['traffic_module_out']
__('In') => (int) $params['traffic_module_in'],
__('Out') => (int) $params['traffic_module_out']
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -69,7 +69,7 @@ $interface_traffic_modules = array(
<head>
<?php
// Parsing the refresh before sending any header
$refresh = (int) get_parameter('refresh', SECONDS_10MINUTES);
$refresh = (int) get_parameter('refresh', SECONDS_5MINUTES);
if ($refresh > 0) {
$query = ui_get_url_refresh(false);
@ -135,8 +135,20 @@ $interface_traffic_modules = array(
else
echo '<div style="margin-left: 50px; padding-top: 10px;">';
$modules = array($interface_traffic_modules['in'], $interface_traffic_modules['out']);
custom_graphs_print(0, $height, $width, $period, null, false, $date, false, 'white', $modules, $config['homeurl']);
custom_graphs_print(0,
$height,
$width,
$period,
null,
false,
$date,
false,
'white',
array_values($interface_traffic_modules),
$config['homeurl'],
array_keys($interface_traffic_modules),
array_fill(0, count($interface_traffic_modules),"bytes/s"),
false);
echo '</div>';