2010-11-23 Miguel de Dios <miguel.dedios@artica.es>
* include/fgraph.php: erased the deprecated function "grafico_modulo_sparseOLD" and deprecated function "grafico_modulo_sparse_mobile". And in the function added new parameter $show_title with default value true for to show or no the title. And when Pandora mobile for the graph now use the function "grafico_modulo_sparse". git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3623 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
3bf75815ba
commit
a804adf875
|
@ -1,3 +1,12 @@
|
|||
2010-11-23 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/fgraph.php: erased the deprecated function
|
||||
"grafico_modulo_sparseOLD" and deprecated function
|
||||
"grafico_modulo_sparse_mobile". And in the function added new
|
||||
parameter $show_title with default value true for to show or no
|
||||
the title. And when Pandora mobile for the graph now use the
|
||||
function "grafico_modulo_sparse".
|
||||
|
||||
2010-11-23 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/javascript/OpenLayers/OpenLayers.js: backport to previous
|
||||
|
|
|
@ -352,166 +352,6 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
|
|||
$engine->combined_graph ($graph, $events, $alerts, $unit_name, $max_value, $stacked);
|
||||
}
|
||||
|
||||
function grafico_modulo_sparseOLD ($id_agente_modulo, $period, $show_event,
|
||||
$width, $height , $title, $unit_name,
|
||||
$show_alert, $avg_only = 0, $pure = false,
|
||||
$date = 0) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
if (empty ($date))
|
||||
$date = get_system_time ();
|
||||
|
||||
$resolution = $config["graph_res"] * 50; // Number of "slices" we want in graph
|
||||
$datelimit = $date - $period;
|
||||
$real_event = array ();
|
||||
|
||||
$interval = (int) ($period / $resolution); // Each interval is $interval seconds length
|
||||
$nombre_agente = get_agentmodule_agent_name ($id_agente_modulo);
|
||||
$id_agente = get_agent_id ($nombre_agente);
|
||||
$nombre_modulo = get_agentmodule_name ($id_agente_modulo);
|
||||
|
||||
// Init tables
|
||||
for ($i = 0; $i <= $resolution; $i++) {
|
||||
$data[$i]['sum'] = 0;
|
||||
$data[$i]['count'] = 0;
|
||||
$data[$i]['timestamp_bottom'] = $datelimit + ($interval * $i);
|
||||
$data[$i]['timestamp_top'] = $datelimit + ($interval * ($i + 1));
|
||||
$data[$i]['min'] = 0;
|
||||
$data[$i]['max'] = 0;
|
||||
$data[$i]['last'] = 0;
|
||||
$data[$i]['events'] = 0;
|
||||
}
|
||||
|
||||
$all_data = get_db_all_rows_filter ('tagente_datos',
|
||||
array ('id_agente_modulo' => (int) $id_agente_modulo,
|
||||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('datos', 'utimestamp'), 'AND', true);
|
||||
|
||||
if ($all_data === false) {
|
||||
if (! $graphic_type) {
|
||||
return fs_error_image ();
|
||||
}
|
||||
graphic_error ();
|
||||
}
|
||||
$max_value = 0;
|
||||
$min_value = 0;
|
||||
$start = 0;
|
||||
foreach ($all_data as $module_data) {
|
||||
$utimestamp = $module_data['utimestamp'];
|
||||
$real_data = $module_data['datos'];
|
||||
for ($i = $start; $i <= $resolution; $i++) {
|
||||
if ($utimestamp <= $data[$i]['timestamp_top'] && $utimestamp >= $data[$i]['timestamp_bottom']) {
|
||||
$start = $i;
|
||||
$data[$i]['sum'] += $real_data;
|
||||
$data[$i]['count']++;
|
||||
$data[$i]['last'] = $real_data;
|
||||
|
||||
// Init min value
|
||||
if ($data[$i]['min'] == 0 || $real_data < $data[$i]['min'])
|
||||
$data[$i]['min'] = $real_data;
|
||||
|
||||
// Check max value
|
||||
if ($real_data > $data[$i]['max'])
|
||||
$data[$i]['max'] = $real_data;
|
||||
|
||||
// Get max value for all graph
|
||||
if ($data[$i]['max'] > $max_value)
|
||||
$max_value = $data[$i]['max'];
|
||||
|
||||
// Get min value for all graph
|
||||
$max_value = max ($max_value, $data[$i]['max']);
|
||||
$min_value = min ($min_value, $data[$i]['min']);
|
||||
|
||||
if ($show_alert == 1) {
|
||||
$alert_high = false;
|
||||
$alert_low = false;
|
||||
// If we want to show alerts limits
|
||||
|
||||
$alert_high = get_db_value ('MAX(max_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo);
|
||||
$alert_low = get_db_value ('MIN(min_value)', 'talert_template_modules', 'id_agent_module', (int) $id_agente_modulo);
|
||||
|
||||
// if no valid alert defined to render limits, disable it
|
||||
if (($alert_low === false || $alert_low === NULL) &&
|
||||
($alert_high === false || $alert_high === NULL)) {
|
||||
$show_alert = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($show_event) {
|
||||
// If we want to show events in graphs
|
||||
$events = get_db_value_filter ('COUNT(*)', 'tevento',
|
||||
array ('id_agentmodule' => $id_agente_modulo,
|
||||
'utimestamp >= '.$data[$i]['timestamp_bottom'],
|
||||
'utimestamp < '.$data[$i]['timestamp_top']));
|
||||
|
||||
if ($events)
|
||||
$data[$i]['events']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the first data outsite (to the left---more old) of the interval given
|
||||
$previous = (float) get_previous_data ($id_agente_modulo, $datelimit);
|
||||
for ($i = 0; $i <= $resolution; $i++) {
|
||||
if ($data[$i]['count']) {
|
||||
$data[$i]['sum'] = $data[$i]['sum'] / $data[$i]['count'];
|
||||
$previous = $data[$i]['last'];
|
||||
} else {
|
||||
$data[$i]['sum'] = $previous;
|
||||
$data[$i]['min'] = $previous;
|
||||
$data[$i]['max'] = $previous;
|
||||
/* Previous does not change here*/
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
if (! $graphic_type) {
|
||||
return fs_module_chart ($data, $width, $height, $avg_only, $resolution / 10, $time_format);
|
||||
}
|
||||
|
||||
$engine = get_graph_engine ($period);
|
||||
$engine->width = $width;
|
||||
$engine->height = $height;
|
||||
$engine->data = &$data;
|
||||
$engine->xaxis_interval = $resolution;
|
||||
if ($title == '')
|
||||
$title = get_agentmodule_name ($id_agente_modulo);
|
||||
$engine->title = ' '.strtoupper ($nombre_agente)." - ".__('Module').' '.$title;
|
||||
$engine->subtitle = ' '.__('Period').': '.$title_period;
|
||||
$engine->show_title = !$pure;
|
||||
$engine->max_value = $max_value;
|
||||
$engine->min_value = $min_value;
|
||||
$engine->events = (bool) $show_event;
|
||||
$engine->alert_top = $show_alert ? $alert_high : false;
|
||||
$engine->alert_bottom = $show_alert ? $alert_low : false;;
|
||||
if (! $pure) {
|
||||
$engine->legend = &$legend;
|
||||
}
|
||||
$engine->fontpath = $config['fontpath'];
|
||||
|
||||
$engine->sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a pie graph with module data of agents
|
||||
*
|
||||
|
@ -1312,7 +1152,7 @@ function progress_bar ($progress, $width, $height, $mode = 1) {
|
|||
function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
||||
$width, $height , $title, $unit_name,
|
||||
$show_alerts, $avg_only = 0, $pure = false,
|
||||
$date = 0, $baseline = 0, $return_data = 0) {
|
||||
$date = 0, $baseline = 0, $return_data = 0, $show_title = true) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
|
@ -1547,7 +1387,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
|||
$engine->xaxis_interval = $resolution;
|
||||
$engine->title = "";
|
||||
$engine->subtitle = $caption;
|
||||
$engine->show_title = true;
|
||||
$engine->show_title = $show_title;
|
||||
$engine->max_value = $max_value;
|
||||
$engine->min_value = $min_value;
|
||||
$engine->events = (bool) $show_events;
|
||||
|
@ -1561,241 +1401,6 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
|
|||
$engine->sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name, $baseline);
|
||||
}
|
||||
|
||||
function grafico_modulo_sparse_mobile ($agent_module_id, $period, $show_events,
|
||||
$width, $height , $title, $unit_name,
|
||||
$show_alerts, $avg_only = 0, $pure = false,
|
||||
$date = 0) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
// Set variables
|
||||
if ($date == 0) $date = get_system_time();
|
||||
$datelimit = $date - $period;
|
||||
$resolution = $config['graph_res'] * 50; //Number of points of the graph
|
||||
$interval = (int) ($period / $resolution);
|
||||
$agent_name = get_agentmodule_agent_name ($agent_module_id);
|
||||
$agent_id = get_agent_id ($agent_name);
|
||||
$module_name = get_agentmodule_name ($agent_module_id);
|
||||
$id_module_type = get_agentmodule_type ($agent_module_id);
|
||||
$module_type = get_moduletype_name ($id_module_type);
|
||||
$uncompressed_module = is_module_uncompressed ($module_type);
|
||||
if ($uncompressed_module) {
|
||||
$avg_only = 1;
|
||||
}
|
||||
|
||||
// Get event data (contains alert data too)
|
||||
if ($show_events == 1 || $show_alerts == 1) {
|
||||
$events = get_db_all_rows_filter ('tevento',
|
||||
array ('id_agentmodule' => $agent_module_id,
|
||||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('evento', 'utimestamp', 'event_type'));
|
||||
if ($events === false) {
|
||||
$events = array ();
|
||||
}
|
||||
}
|
||||
|
||||
// Get module data
|
||||
$data = get_db_all_rows_filter ('tagente_datos',
|
||||
array ('id_agente_modulo' => $agent_module_id,
|
||||
"utimestamp > $datelimit",
|
||||
"utimestamp < $date",
|
||||
'order' => 'utimestamp ASC'),
|
||||
array ('datos', 'utimestamp'));
|
||||
if ($data === false) {
|
||||
$data = array ();
|
||||
}
|
||||
|
||||
// Uncompressed module data
|
||||
if ($uncompressed_module) {
|
||||
$min_necessary = 1;
|
||||
|
||||
// Compressed module data
|
||||
} else {
|
||||
// Get previous data
|
||||
$previous_data = get_previous_data ($agent_module_id, $datelimit);
|
||||
if ($previous_data !== false) {
|
||||
$previous_data['utimestamp'] = $datelimit;
|
||||
array_unshift ($data, $previous_data);
|
||||
}
|
||||
|
||||
// Get next data
|
||||
$nextData = get_next_data ($agent_module_id, $date);
|
||||
if ($nextData !== false) {
|
||||
array_push ($data, $nextData);
|
||||
} else if (count ($data) > 0) {
|
||||
// Propagate the last known data to the end of the interval
|
||||
$nextData = array_pop ($data);
|
||||
array_push ($data, $nextData);
|
||||
$nextData['utimestamp'] = $date;
|
||||
array_push ($data, $nextData);
|
||||
}
|
||||
|
||||
$min_necessary = 2;
|
||||
}
|
||||
|
||||
// Check available data
|
||||
if (count ($data) < $min_necessary) {
|
||||
if (!$graphic_type) {
|
||||
return fs_error_image ();
|
||||
}
|
||||
graphic_error ();
|
||||
}
|
||||
|
||||
// Data iterator
|
||||
$j = 0;
|
||||
|
||||
// Event iterator
|
||||
$k = 0;
|
||||
|
||||
// Set initial conditions
|
||||
$chart = array();
|
||||
if ($data[0]['utimestamp'] == $datelimit) {
|
||||
$previous_data = $data[0]['datos'];
|
||||
$j++;
|
||||
} else {
|
||||
$previous_data = 0;
|
||||
}
|
||||
|
||||
// Calculate chart data
|
||||
for ($i = 0; $i < $resolution; $i++) {
|
||||
$timestamp = $datelimit + ($interval * $i);
|
||||
|
||||
$total = 0;
|
||||
$count = 0;
|
||||
|
||||
// Read data that falls in the current interval
|
||||
$interval_min = false;
|
||||
$interval_max = false;
|
||||
while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) {
|
||||
if ($interval_min === false) {
|
||||
$interval_min = $data[$j]['datos'];
|
||||
}
|
||||
if ($interval_max === false) {
|
||||
$interval_max = $data[$j]['datos'];
|
||||
}
|
||||
|
||||
if ($data[$j]['datos'] > $interval_max) {
|
||||
$interval_max = $data[$j]['datos'];
|
||||
} else if ($data[$j]['datos'] < $interval_max) {
|
||||
$interval_min = $data[$j]['datos'];
|
||||
}
|
||||
$total += $data[$j]['datos'];
|
||||
$count++;
|
||||
$j++;
|
||||
}
|
||||
|
||||
// Data in the interval
|
||||
if ($count > 0) {
|
||||
$total /= $count;
|
||||
}
|
||||
|
||||
// Read events and alerts that fall in the current interval
|
||||
$event_value = 0;
|
||||
$alert_value = 0;
|
||||
|
||||
while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
|
||||
if ($show_events == 1) {
|
||||
$event_value++;
|
||||
}
|
||||
if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
|
||||
$alert_value++;
|
||||
}
|
||||
$k++;
|
||||
}
|
||||
|
||||
// Data
|
||||
if ($count > 0) {
|
||||
$chart[$timestamp]['sum'] = $total;
|
||||
$chart[$timestamp]['min'] = $interval_min;
|
||||
$chart[$timestamp]['max'] = $interval_max;
|
||||
$previous_data = $total;
|
||||
// Compressed data
|
||||
} else {
|
||||
if ($uncompressed_module || ($timestamp > time ())) {
|
||||
$chart[$timestamp]['sum'] = 0;
|
||||
$chart[$timestamp]['min'] = 0;
|
||||
$chart[$timestamp]['max'] = 0;
|
||||
} else {
|
||||
$chart[$timestamp]['sum'] = $previous_data;
|
||||
$chart[$timestamp]['min'] = $previous_data;
|
||||
$chart[$timestamp]['max'] = $previous_data;
|
||||
}
|
||||
}
|
||||
|
||||
$chart[$timestamp]['count'] = 0;
|
||||
$chart[$timestamp]['timestamp_bottom'] = $timestamp;
|
||||
$chart[$timestamp]['timestamp_top'] = $timestamp + $interval;
|
||||
$chart[$timestamp]['events'] = $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) {
|
||||
if ($chart_data['events'] > 0) {
|
||||
$chart[$timestamp]['events'] = $event_max;
|
||||
}
|
||||
if ($chart_data['alert'] > 0) {
|
||||
$chart[$timestamp]['alert'] = $event_max;
|
||||
}
|
||||
}
|
||||
|
||||
// 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';
|
||||
}
|
||||
|
||||
// Flash chart
|
||||
$caption = __('Max. Value') . ': ' . $max_value . ' ' . __('Avg. Value') . ': ' . $avg_value . ' ' . __('Min. Value') . ': ' . $min_value;
|
||||
if (! $graphic_type) {
|
||||
return fs_module_chart ($chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption);
|
||||
}
|
||||
|
||||
$engine = get_graph_engine ($period);
|
||||
$engine->width = $width;
|
||||
$engine->height = $height;
|
||||
$engine->data = &$chart;
|
||||
$engine->xaxis_interval = $resolution * 1.8;
|
||||
$engine->title = "";
|
||||
$engine->subtitle = $caption;
|
||||
$engine->show_title = false; //true;
|
||||
$engine->max_value = $max_value;
|
||||
$engine->min_value = $min_value;
|
||||
$engine->events = (bool) $show_events;
|
||||
$engine->alert_top = false;
|
||||
$engine->alert_bottom = false;;
|
||||
if (! $pure) {
|
||||
$engine->legend = &$legend;
|
||||
}
|
||||
$engine->fontpath = $config['fontpath'];
|
||||
|
||||
$engine->sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name);
|
||||
}
|
||||
|
||||
function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
|
||||
$width, $height , $title, $unit_name, $show_alerts, $avg_only = 0, $pure=0,
|
||||
$date = 0 ) {
|
||||
|
@ -2761,9 +2366,10 @@ if ($graphic_type) {
|
|||
grafico_modulo_sparse ($id, $period, $draw_events, $width, $height,
|
||||
$label, $unit_name, $draw_alerts, $avg_only, $pure, $date, $baseline);
|
||||
break;
|
||||
case 'sparse_mobile':
|
||||
grafico_modulo_sparse_mobile ($id, $period, $draw_events, $width, $height,
|
||||
$label, $unit_name, $draw_alerts, $avg_only, $pure, $date);
|
||||
case 'sparse_mobile':
|
||||
grafico_modulo_sparse($id, $period, $draw_events, $width, $height,
|
||||
$label, $unit_name, $draw_alerts, $avg_only, $pure, $date,
|
||||
0, 0, false);
|
||||
break;
|
||||
case "boolean":
|
||||
grafico_modulo_boolean ($id, $period, $draw_events, $width, $height ,
|
||||
|
|
Loading…
Reference in New Issue