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

* include/fgraph.php: Improved the speed of chart drawing algorithms.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2809 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2010-05-27 12:06:18 +00:00
parent c5b7ffde73
commit ec76e84889
2 changed files with 94 additions and 73 deletions

View File

@ -1,3 +1,7 @@
2010-05-27 Ramon Novoa <rnovoa@artica.es>
* include/fgraph.php: Improved the speed of chart drawing algorithms.
2010-05-27 Sergio Martin <sergio.martin@artica.es> 2010-05-27 Sergio Martin <sergio.martin@artica.es>
* operation/users/user_edit.php: Fixed the message * operation/users/user_edit.php: Fixed the message

View File

@ -137,8 +137,8 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
} }
// Set data containers // Set data containers
for ($iterator = 0; $iterator < $resolution; $iterator++) { for ($i = 0; $i < $resolution; $i++) {
$timestamp = $datelimit + ($interval * $iterator); $timestamp = $datelimit + ($interval * $i);
$graph[$timestamp]['count'] = 0; $graph[$timestamp]['count'] = 0;
$graph[$timestamp]['timestamp_bottom'] = $timestamp; $graph[$timestamp]['timestamp_bottom'] = $timestamp;
@ -208,23 +208,29 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
} }
graphic_error (); graphic_error ();
} }
// Data iterator
$j = 0;
// Event iterator
$k = 0;
// Calculate chart data // Set initial conditions
$graph_values[$i] = array(); $graph_values[$i] = array();
$module_data = array_shift ($data); if ($data[0]['utimestamp'] == $datelimit) {
$event_data = array_shift ($events); $previous_data = $data[0]['datos'];
if ($module_data['utimestamp'] == $datelimit) { $min_value = $data[0]['datos'];
$previous_data = $module_data['datos']; $max_value = $data[0]['datos'];
$min_value = $module_data['datos']; $j++;
$max_value = $module_data['datos'];
} else { } else {
$previous_data = 0; $previous_data = 0;
$min_value = 0; $min_value = 0;
$max_value = 0; $max_value = 0;
} }
for ($iterator = 0; $iterator < $resolution; $iterator++) { // Calculate chart data
$timestamp = $datelimit + ($interval * $iterator); for ($l = 0; $l < $resolution; $l++) {
$timestamp = $datelimit + ($interval * $l);
$total = 0; $total = 0;
$count = 0; $count = 0;
@ -232,15 +238,15 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
// Read data that falls in the current interval // Read data that falls in the current interval
$interval_min = $previous_data; $interval_min = $previous_data;
$interval_max = $previous_data; $interval_max = $previous_data;
while ($module_data !== null && $module_data ['utimestamp'] >= $timestamp && $module_data ['utimestamp'] < ($timestamp + $interval)) { while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) {
if ($module_data['datos'] > $interval_max) { if ($data[$j]['datos'] > $interval_max) {
$interval_max = $module_data['datos']; $interval_max = $data[$j]['datos'];
} else if ($module_data['datos'] < $interval_max) { } else if ($data[$j]['datos'] < $interval_max) {
$interval_min = $module_data['datos']; $interval_min = $data[$j]['datos'];
} }
$total += $module_data['datos']; $total += $data[$j]['datos'];
$count++; $count++;
$module_data = array_shift ($data); $j++;
} }
// Average // Average
@ -258,14 +264,14 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
// Read events and alerts that fall in the current interval // Read events and alerts that fall in the current interval
$event_value = 0; $event_value = 0;
$alert_value = 0; $alert_value = 0;
while ($event_data !== null && $event_data ['utimestamp'] >= $timestamp && $event_data ['utimestamp'] <= ($timestamp + $interval)) { while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
if ($show_events == 1) { if ($show_events == 1) {
$event_value++; $event_value++;
} }
if ($show_alerts == 1 && substr ($event_data['event_type'], 0, 5) == 'alert') { if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
$alert_value++; $alert_value++;
} }
$event_data = array_shift ($events); $k++;
} }
// Data // Data
@ -301,13 +307,6 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
$time_format = 'M j'; $time_format = 'M j';
} }
if ($max_value <= 0) {
if (! $graphic_type) {
return fs_error_image ();
}
graphic_error ();
}
if (! $graphic_type) { if (! $graphic_type) {
return fs_combined_chart ($graph_values, $graph, $module_name_list, $width, $height, $stacked, $resolution / 10, $time_format); return fs_combined_chart ($graph_values, $graph, $module_name_list, $width, $height, $stacked, $resolution / 10, $time_format);
} }
@ -1327,22 +1326,28 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
graphic_error (); graphic_error ();
} }
// Calculate chart data // Data iterator
$j = 0;
// Event iterator
$k = 0;
// Set initial conditions
$chart = array(); $chart = array();
$module_data = array_shift ($data); if ($data[0]['utimestamp'] == $datelimit) {
$event_data = array_shift ($events); $previous_data = $data[0]['datos'];
if ($module_data['utimestamp'] == $datelimit) { $min_value = $data[0]['datos'];
$previous_data = $module_data['datos']; $max_value = $data[0]['datos'];
$min_value = $module_data['datos']; $j++;
$max_value = $module_data['datos'];
} else { } else {
$previous_data = 0; $previous_data = 0;
$min_value = 0; $min_value = 0;
$max_value = 0; $max_value = 0;
} }
for ($iterator = 0; $iterator < $resolution; $iterator++) { // Calculate chart data
$timestamp = $datelimit + ($interval * $iterator); for ($i = 0; $i < $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
$total = 0; $total = 0;
$count = 0; $count = 0;
@ -1350,15 +1355,15 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
// Read data that falls in the current interval // Read data that falls in the current interval
$interval_min = $previous_data; $interval_min = $previous_data;
$interval_max = $previous_data; $interval_max = $previous_data;
while ($module_data !== null && $module_data ['utimestamp'] >= $timestamp && $module_data ['utimestamp'] < ($timestamp + $interval)) { while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) {
if ($module_data['datos'] > $interval_max) { if ($data[$j]['datos'] > $interval_max) {
$interval_max = $module_data['datos']; $interval_max = $data[$j]['datos'];
} else if ($module_data['datos'] < $interval_max) { } else if ($data[$j]['datos'] < $interval_max) {
$interval_min = $module_data['datos']; $interval_min = $data[$j]['datos'];
} }
$total += $module_data['datos']; $total += $data[$j]['datos'];
$count++; $count++;
$module_data = array_shift ($data); $j++;
} }
// Average // Average
@ -1376,14 +1381,14 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
// Read events and alerts that fall in the current interval // Read events and alerts that fall in the current interval
$event_value = 0; $event_value = 0;
$alert_value = 0; $alert_value = 0;
while ($event_data !== null && $event_data ['utimestamp'] >= $timestamp && $event_data ['utimestamp'] <= ($timestamp + $interval)) { while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
if ($show_events == 1) { if ($show_events == 1) {
$event_value++; $event_value++;
} }
if ($show_alerts == 1 && substr ($event_data['event_type'], 0, 5) == 'alert') { if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
$alert_value++; $alert_value++;
} }
$event_data = array_shift ($events); $k++;
} }
// Data // Data
@ -1531,35 +1536,41 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
graphic_error (); graphic_error ();
} }
// Calculate chart data // Data iterator
$j = 0;
// Event iterator
$k = 0;
// Set initial conditions
$chart = array(); $chart = array();
$module_data = array_shift ($data); if ($data[0]['utimestamp'] == $datelimit) {
$event_data = array_shift ($events); $previous_data = $data[0]['datos'];
if ($module_data['utimestamp'] == $datelimit) { $max_value = $data[0]['datos'];
$previous_data = $module_data['datos']; $j++;
$max_value = $module_data['datos'];
} else { } else {
$previous_data = 0; $previous_data = 0;
$max_value = 0; $max_value = 0;
} }
for ($iterator = 0; $iterator < $resolution; $iterator++) { // Calculate chart data
$timestamp = $datelimit + ($interval * $iterator); for ($i = 0; $i < $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
$zero = 0; $zero = 0;
$total = 0; $total = 0;
$count = 0; $count = 0;
// Read data that falls in the current interval // Read data that falls in the current interval
while ($module_data !== null && $module_data ['utimestamp'] >= $timestamp && $module_data ['utimestamp'] <= ($timestamp + $interval)) { while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] <= ($timestamp + $interval)) {
if ($module_data['datos'] == 0) { if ($data[$j]['datos'] == 0) {
$zero = 1; $zero = 1;
} else { } else {
$total += $module_data['datos']; $total += $data[$j]['datos'];
$count++; $count++;
} }
$module_data = array_shift ($data); $j++;
} }
// Average // Average
@ -1575,14 +1586,14 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
// Read events and alerts that fall in the current interval // Read events and alerts that fall in the current interval
$event_value = 0; $event_value = 0;
$alert_value = 0; $alert_value = 0;
while ($event_data !== null && $event_data ['utimestamp'] >= $timestamp && $event_data ['utimestamp'] < ($timestamp + $interval)) { while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] < ($timestamp + $interval)) {
if ($show_events == 1) { if ($show_events == 1) {
$event_value++; $event_value++;
} }
if ($show_alerts == 1 && substr ($event_data['event_type'], 0, 5) == 'alert') { if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
$alert_value++; $alert_value++;
} }
$event_data = array_shift ($events); $k++;
} }
// Data and zeroes (draw a step) // Data and zeroes (draw a step)
@ -1766,26 +1777,32 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
graphic_error (); graphic_error ();
} }
// Calculate chart data // Data iterator
$j = 0;
// Event iterator
$k = 0;
// Set initial conditions
$chart = array(); $chart = array();
$module_data = array_shift ($data); if ($data[0]['utimestamp'] == $datelimit) {
$event_data = array_shift ($events);
if ($module_data['utimestamp'] == $datelimit) {
$previous_data = 1; $previous_data = 1;
$max_value = 1; $max_value = 1;
$j++;
} else { } else {
$previous_data = 0; $previous_data = 0;
$max_value = 0; $max_value = 0;
} }
for ($iterator = 0; $iterator < $resolution; $iterator++) { // Calculate chart data
$timestamp = $datelimit + ($interval * $iterator); for ($i = 0; $i < $resolution; $i++) {
$timestamp = $datelimit + ($interval * $i);
$count = 0; $count = 0;
// Read data that falls in the current interval // Read data that falls in the current interval
while ($module_data !== null && $module_data ['utimestamp'] >= $timestamp && $module_data ['utimestamp'] <= ($timestamp + $interval)) { while (isset ($data[$j]) !== null && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] <= ($timestamp + $interval)) {
$count++; $count++;
$module_data = array_shift ($data); $j++;
} }
// Max // Max
@ -1796,14 +1813,14 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
// Read events and alerts that fall in the current interval // Read events and alerts that fall in the current interval
$event_value = 0; $event_value = 0;
$alert_value = 0; $alert_value = 0;
while ($event_data !== null && $event_data ['utimestamp'] >= $timestamp && $event_data ['utimestamp'] <= ($timestamp + $interval)) { while (isset ($events[$k]) && $events[$k]['utimestamp'] >= $timestamp && $events[$k]['utimestamp'] <= ($timestamp + $interval)) {
if ($show_events == 1) { if ($show_events == 1) {
$event_value++; $event_value++;
} }
if ($show_alerts == 1 && substr ($event_data['event_type'], 0, 5) == 'alert') { if ($show_alerts == 1 && substr ($events[$k]['event_type'], 0, 5) == 'alert') {
$alert_value++; $alert_value++;
} }
$event_data = array_shift ($events); $k++;
} }
// Data in the interval // Data in the interval