2010-05-07 Ramon Novoa <rnovoa@artica.es>

* include/functions_reporting.php, include/fgraph.php,
          include/functions_db.php, include/functions_fsgraph.php: Fixed
          a lot of chart and report code related to Pandora FMS's data
          compression algorithm.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2678 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2010-05-07 18:18:23 +00:00
parent c119e3d8c6
commit 942ee05e8b
5 changed files with 850 additions and 579 deletions

View File

@ -1,3 +1,10 @@
2010-05-07 Ramon Novoa <rnovoa@artica.es>
* include/functions_reporting.php, include/fgraph.php,
include/functions_db.php, include/functions_fsgraph.php: Fixed
a lot of chart and report code related to Pandora FMS's data
compression algorithm.
2010-05-07 Sergio Martin <sergio.martin@artica.es> 2010-05-07 Sergio Martin <sergio.martin@artica.es>
* godmode/servers/manage_recontask_form.php: Included * godmode/servers/manage_recontask_form.php: Included

File diff suppressed because it is too large Load Diff

View File

@ -2508,22 +2508,27 @@ function get_layoutdata_y ($id_layoutdata){
* *
* @param int Agent module id * @param int Agent module id
* @param int The timestamp to look backwards from and get the data. * @param int The timestamp to look backwards from and get the data.
* @param int 1 if the module has a string type.
* *
* @return mixed The row of tagente_datos of the last period. False if there were no data. * @return mixed The row of tagente_datos of the last period. False if there were no data.
*/ */
function get_previous_data ($id_agent_module, $utimestamp = 0) { function get_previous_data ($id_agent_module, $utimestamp = 0, $string = 0) {
if (empty ($utimestamp)) if (empty ($utimestamp))
$utimestamp = time (); $utimestamp = time ();
if ($string == 1) {
$table = 'tagente_datos_string';
} else {
$table = 'tagente_datos';
}
// 172800 = 60×60×24*2 Search up to 2 days before utimestamp // 172800 = 60×60×24*2 Search up to 2 days before utimestamp
$interval = get_module_interval ($id_agent_module); $sql = sprintf ('SELECT * FROM ' . $table . ' WHERE id_agente_modulo = %d
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp <= %d AND utimestamp <= %d
AND utimestamp >= %d AND utimestamp >= %d
ORDER BY utimestamp DESC', ORDER BY utimestamp DESC',
$id_agent_module, $utimestamp, $utimestamp - 172800); $id_agent_module, $utimestamp, $utimestamp - 172800);
return get_db_row_sql ($sql, true); return get_db_row_sql ($sql, true);
} }
@ -2532,12 +2537,19 @@ function get_previous_data ($id_agent_module, $utimestamp = 0) {
* *
* @param int Agent module id * @param int Agent module id
* @param int The timestamp to look backwards from and get the data. * @param int The timestamp to look backwards from and get the data.
* * @param int 1 if the module has a string type.
*
* @return mixed The row of tagente_datos of the last period. False if there were no data. * @return mixed The row of tagente_datos of the last period. False if there were no data.
*/ */
function get_next_data ($id_agent_module, $utimestamp = 0) { function get_next_data ($id_agent_module, $utimestamp = 0, $string = 0) {
if (empty ($utimestamp)) if (empty ($utimestamp))
$utimestamp = time (); $utimestamp = time ();
if ($string == 1) {
$table = 'tagente_datos_string';
} else {
$table = 'tagente_datos';
}
$interval = get_module_interval ($id_agent_module); $interval = get_module_interval ($id_agent_module);
$sql = sprintf ('SELECT * FROM tagente_datos $sql = sprintf ('SELECT * FROM tagente_datos

View File

@ -131,7 +131,7 @@ function fs_2d_area_chart ($data, $width, $height, $step = 1, $params = '') {
} }
// Returns a Pandora FMS module chart // Returns a Pandora FMS module chart
function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i') { function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $time_format = 'G:i', $show_events = 0, $show_alerts = 0) {
global $config; global $config;
// Generate the XML // Generate the XML
@ -150,9 +150,25 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
$chart->addCategory(date($time_format, $value['timestamp_bottom']), 'hoverText=' . date ($config['date_format'], $value['timestamp_bottom']) . ';showName=' . $show_name); $chart->addCategory(date($time_format, $value['timestamp_bottom']), 'hoverText=' . date ($config['date_format'], $value['timestamp_bottom']) . ';showName=' . $show_name);
} }
// Event chart
if ($show_events == 1) {
$chart->addDataSet(__('Events'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff7f00;color=#ff7f00');
foreach ($data as $value) {
$chart->addChartData($value['event']);
}
}
// Alert chart
if ($show_alerts == 1) {
$chart->addDataSet(__('Alerts'), 'alpha=50;showAreaBorder=1;areaBorderColor=#ff0000;color=#ff0000');
foreach ($data as $value) {
$chart->addChartData($value['alert']);
}
}
// Max chart // Max chart
if ($avg_only == 0) { if ($avg_only == 0) {
$chart->addDataSet('Max', 'color=' . $config['graph_color3']); $chart->addDataSet(__('Max'), 'color=' . $config['graph_color3']);
foreach ($data as $value) { foreach ($data as $value) {
$chart->addChartData($value['max']); $chart->addChartData($value['max']);
} }
@ -160,7 +176,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
// Avg chart // Avg chart
$empty = 1; $empty = 1;
$chart->addDataSet('Avg', 'color=' . $config['graph_color2']); $chart->addDataSet(__('Avg'), 'color=' . $config['graph_color2']);
foreach ($data as $value) { foreach ($data as $value) {
if ($value['sum'] > 0) { if ($value['sum'] > 0) {
$empty = 0; $empty = 0;
@ -170,7 +186,7 @@ function fs_module_chart ($data, $width, $height, $avg_only = 1, $step = 10, $ti
// Min chart // Min chart
if ($avg_only == 0) { if ($avg_only == 0) {
$chart->addDataSet('Min', 'color=' . $config['graph_color1']); $chart->addDataSet(__('Min'), 'color=' . $config['graph_color1']);
foreach ($data as $value) { foreach ($data as $value) {
$chart->addChartData($value['min']); $chart->addChartData($value['min']);
} }

View File

@ -37,50 +37,58 @@ require_once ($config["homedir"]."/include/functions_agents.php");
* @return float The average module value in the interval. * @return float The average module value in the interval.
*/ */
function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) { function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
if ($date < 1) { global $config;
$date = get_system_time ();
}
$datelimit = $date - $period; // Initialize variables
if (empty ($date)) $date = get_system_time ();
$sql = sprintf ("SELECT * FROM tagente_datos if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"];
WHERE id_agente_modulo = %d $datelimit = $date - $period;
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$values = get_db_all_rows_sql ($sql, true);
if ($values === false) {
$values = array ();
}
/* Get also the previous data before the selected interval. */ // Get module data
$sum = 0; $interval_data = get_db_all_rows_sql ('SELECT * FROM tagente_datos
$total = 0; WHERE id_agente_modulo = ' . (int) $id_agent_module .
$module_interval = get_module_interval ($id_agent_module); ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = get_previous_data ($id_agent_module, $datelimit); $previous_data = get_previous_data ($id_agent_module, $datelimit);
if (($previous_data !== false) && (isset($interval_data))) { if ($previous_data !== false) {
array_unshift ($interval_data, $values); $previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
} }
foreach ($values as $data) { // Get next data
$interval_total = 1; $next_data = get_next_data ($id_agent_module, $date);
$interval_sum = $data['datos']; if ($next_data !== false) {
if ($previous_data !== false && $data['utimestamp'] - $previous_data['utimestamp'] > $module_interval) { $next_data['utimestamp'] = $date;
$interval_total = round (($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval, 0); array_push ($interval_data, $next_data);
$interval_sum *= $interval_total; } else {
// Propagate the last known data to the end of the interval
} $next_data = array_pop ($interval_data);
$total += $interval_total; array_push ($interval_data, $next_data);
$sum += $interval_sum; $next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return -1;
}
// Set initial conditions
$total = 0;
$previous_data = array_shift ($interval_data);
foreach ($interval_data as $data) {
$total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']);
$previous_data = $data; $previous_data = $data;
} }
if ($total == 0) { if ($period == 0) {
return 0; return 0;
} }
return $sum / $total; return $total / $period;
} }
/** /**
@ -93,22 +101,59 @@ function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
* @return float The maximum module value in the interval. * @return float The maximum module value in the interval.
*/ */
function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) { function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) {
if (! $date) global $config;
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos // Initialize variables
WHERE id_agente_modulo = %d if (empty ($date)) $date = get_system_time ();
AND utimestamp > %d AND utimestamp <= %d", if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"];
$id_agent_module, $datelimit, $date); $datelimit = $date - $period;
$max = (float) get_db_sql ($sql, 0, true);
// Get module data
/* Get also the previous report before the selected interval. */ $interval_data = get_db_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = get_previous_data ($id_agent_module, $datelimit); $previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) if ($previous_data !== false) {
return max ($previous_data['datos'], $max); $previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
return max ((float) $previous_data, $max); }
// Get next data
$next_data = get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
} else {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return -1;
}
// Set initial conditions
$previous_data = array_shift ($interval_data);
if ($previous_data['utimestamp'] == $datelimit) {
$max = $previous_data['datos'];
} else {
$max = 0;
}
foreach ($interval_data as $data) {
if ($data['datos'] > $max) {
$max = $data['datos'];
}
}
return $max;
} }
/** /**
@ -121,20 +166,58 @@ function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) {
* @return float The minimum module value of the module * @return float The minimum module value of the module
*/ */
function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) { function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
if (! $date) global $config;
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos // Initialize variables
WHERE id_agente_modulo = %d if (empty ($date)) $date = get_system_time ();
AND utimestamp > %d AND utimestamp <= %d", if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"];
$id_agent_module, $datelimit, $date); $datelimit = $date - $period;
$min = (float) get_db_sql ($sql, 0, true);
// Get module data
/* Get also the previous data before the selected interval. */ $interval_data = get_db_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', true);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = get_previous_data ($id_agent_module, $datelimit); $previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) if ($previous_data !== false) {
return min ($previous_data['datos'], $min); $previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
} else {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return -1;
}
// Set initial conditions
$previous_data = array_shift ($interval_data);
if ($previous_data['utimestamp'] == $datelimit) {
$min = $previous_data['datos'];
} else {
$min = 0;
}
foreach ($interval_data as $data) {
if ($data['datos'] < $min) {
$min = $data['datos'];
}
}
return $min; return $min;
} }
@ -149,77 +232,68 @@ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
*/ */
function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) { function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
if (! $date) // Initialize variables
$date = get_system_time (); if (empty ($date)) $date = get_system_time ();
if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"];
$datelimit = $date - $period; // limit date $datelimit = $date - $period;
$id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module); $id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type); $module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type);
$module_interval = get_module_interval ($id_agent_module);
// Wrong module type
if (is_module_data_string ($module_name)) { if (is_module_data_string ($module_name)) {
return 0; return 0;
// Wrong module type, we cannot sum alphanumerical data !
} }
// Get the whole interval of data // Incremental modules are treated differently
$sql = sprintf ('SELECT utimestamp, datos FROM tagente_datos $module_inc = is_module_inc ($module_name);
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d // Get module data
ORDER BY utimestamp ASC', $interval_data = get_db_all_rows_sql ('SELECT * FROM tagente_datos
$id_agent_module, $datelimit, $date); WHERE id_agente_modulo = ' . (int) $id_agent_module .
$datas = get_db_all_rows_sql ($sql, true); ' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
/* Get also the previous data before the selected interval. */ ' ORDER BY utimestamp ASC', true);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = get_previous_data ($id_agent_module, $datelimit); $previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) { if ($previous_data !== false) {
/* Add data to the beginning */ $previous_data['utimestamp'] = $datelimit;
array_unshift ($datas, $previous_data); array_unshift ($interval_data, $previous_data);
}
if ($datas === false) {
return 0;
} }
$last_data = ""; // Get next data
$total_badtime = 0; $next_data = get_next_data ($id_agent_module, $date);
$module_interval = get_module_interval ($id_agent_module); if ($next_data !== false) {
$timestamp_begin = $datelimit + $module_interval; $next_data['utimestamp'] = $date;
$timestamp_end = 0; array_push ($interval_data, $next_data);
$sum = 0; } else {
$data_value = 0; // Propagate the last known data to the end of the interval
$elapsed = 1; $next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
foreach ($datas as $data) { $next_data['utimestamp'] = $date;
$timestamp_end = $data["utimestamp"]; array_push ($interval_data, $next_data);
if ($timestamp_begin < $timestamp_end) }
$elapsed = $timestamp_end - $timestamp_begin;
$times = $elapsed / $module_interval;
if (is_module_inc ($module_name)) { if (count ($interval_data) < 2) {
$data_value = $data['datos'] * $module_interval; return -1;
}
// Set initial conditions
$total = 0;
$previous_data = array_shift ($interval_data);
foreach ($interval_data as $data) {
if ($module_inc) {
$total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']);
} else { } else {
$data_value = $data['datos']; $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval;
} }
$previous_data = $data;
$sum += $times * $data_value;
$timestamp_begin = $data["utimestamp"];
} }
/* The last value must be get from tagente_estado, but return $total;
it will count only if it's not older than date demanded
*/
$timestamp_end = get_db_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module);
if ($timestamp_end <= $datelimit) {
$elapsed = $timestamp_end - $timestamp_begin;
$times = intval ($elapsed / $module_interval);
if (is_module_inc ($module_name)) {
$data_value = $data['datos'] * $module_interval;
} else {
$data_value = $data['datos'];
}
$sum += $times * $data_value;
}
return (float) $sum;
} }
/** /**
@ -235,7 +309,7 @@ function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
* @return float SLA percentage of the requested module. False if no data were * @return float SLA percentage of the requested module. False if no data were
* found * found
*/ */
function get_agentmodule_sla ($id_agentmodule, $period = 0, $min_value = 1, $max_value = false, $date = 0) { function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0) {
global $config; global $config;
// Initialize variables // Initialize variables
@ -249,19 +323,19 @@ function get_agentmodule_sla ($id_agentmodule, $period = 0, $min_value = 1, $max
$sql = sprintf ('SELECT * FROM tagente_datos $sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d', AND utimestamp > %d AND utimestamp <= %d',
$id_agentmodule, $datelimit, $date); $id_agent_module, $datelimit, $date);
$interval_data = get_db_all_rows_sql ($sql, true); $interval_data = get_db_all_rows_sql ($sql, true);
if ($interval_data === false) $interval_data = array (); if ($interval_data === false) $interval_data = array ();
// Get previous data // Get previous data
$previous_data = get_previous_data ($id_agentmodule, $datelimit); $previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) { if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit; $previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data); array_unshift ($interval_data, $previous_data);
} }
// Get next data // Get next data
$next_data = get_next_data ($id_agentmodule, $date); $next_data = get_next_data ($id_agent_module, $date);
if ($next_data !== false) { if ($next_data !== false) {
$next_data['utimestamp'] = $date; $next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data); array_push ($interval_data, $next_data);