Skip to content

Commit

Permalink
Improvements on the combined graphs
Browse files Browse the repository at this point in the history
* pandora_console/operation/agentes/interface_traffic_graph_win.php:
	Modified the graph function call. Modified the refresh time.

* pandora_console/include/functions_graph.php: Modified the function
	"graphic_combined_module". Now is possible to set the items
	name and choose which values will appear on the items list.

* pandora_console/include/functions_custom_graphs.php: Added new
	parameters to the function "custom_graphs_print" to call the
	function "graphic_combined_module".
  • Loading branch information
alexgallardo committed Sep 22, 2014
1 parent 016a353 commit eb590aa
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 48 deletions.
22 changes: 19 additions & 3 deletions pandora_console/include/functions_custom_graphs.php
Expand Up @@ -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(), $show_last = true, $show_max = true,
$show_min = true, $show_avg = true) {

global $config;

Expand Down Expand Up @@ -214,7 +225,12 @@ function custom_graphs_print($id_graph, $height, $width, $period,
1,
false,
false,
$background_color);
$background_color,
$name_list,
$show_last,
$show_max,
$show_min,
$show_avg);

if ($return)
return $output;
Expand Down
102 changes: 62 additions & 40 deletions pandora_console/include/functions_graph.php
Expand Up @@ -854,14 +854,21 @@ 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 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 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(), $show_last = true, $show_max = true,
$show_min = true, $show_avg = true) {

global $config;
global $graphic_type;
Expand Down Expand Up @@ -971,44 +978,55 @@ function graphic_combined_module ($module_list, $weight_list, $period,
if ($projection != false && $i != 0) {
$agent_module_id = $module_list[0];

//Get and process agent name
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($agent_module_id));
$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);


$agent_id = agents_get_agent_id ($agent_name);


//Get and process module name
$module_name = io_safe_output(
modules_get_agentmodule_name ($agent_module_id));
$module_name = sprintf(__("projection for %s"), $module_name);
$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);

if (!empty($name_list) && 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));
$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);


$agent_id = agents_get_agent_id ($agent_name);


//Get and process module name
$module_name = io_safe_output(
modules_get_agentmodule_name ($agent_module_id));
$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;
}

$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);
}
else {
$agent_module_id = $module_list[$i];

//Get and process agent name
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($agent_module_id));
$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);


$agent_id = agents_get_agent_id ($agent_name);

//Get and process module name
$module_name = io_safe_output(
modules_get_agentmodule_name ($agent_module_id));
$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);

$module_name_list[$i] = $agent_name . " / " . $module_name;
if (!empty($name_list) && 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));
$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);


$agent_id = agents_get_agent_id ($agent_name);

//Get and process module name
$module_name = io_safe_output(
modules_get_agentmodule_name ($agent_module_id));
$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);
Expand Down Expand Up @@ -1199,18 +1217,22 @@ function graphic_combined_module ($module_list, $weight_list, $period,

$graph_stats = get_graph_statistics($graph_values[$i]);

$min = $graph_stats['min'];
$max = $graph_stats['max'];
$avg = $graph_stats['avg'];
$last = $graph_stats['last'];
$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);
$units = 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 $units; ";
if ($show_max)
$module_name_list[$i] .= __("Max") . ": $max $units; ";
if ($show_min)
$module_name_list[$i] .= __("Min") . ": $min $units; ";
if ($show_avg)
$module_name_list[$i] .= __("Avg") . ": $avg $units";
}

if ($weight_list[$i] != 1) {
Expand Down
21 changes: 16 additions & 5 deletions pandora_console/operation/agentes/interface_traffic_graph_win.php
Expand Up @@ -60,16 +60,16 @@
$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">
<html xmlns="http://www.w3.org/1999/xhtml">
<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);

Expand Down Expand Up @@ -135,8 +135,19 @@ function show_others() {
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),
false);

echo '</div>';

Expand Down

0 comments on commit eb590aa

Please sign in to comment.