2011-04-05 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_fsgraph.php, include/functions_graph.php, include/graphs/functions_utils.php, include/fgraph.php: cleaned source code style. * include/functions_graph.php: added first version of function "graphic_combined_module2". * include/graphs/functions_pchart.php: fixed when pass a empty array as colour for graphs. * include/graphs/pChart/pDraw.class.php: fixed to set a color border when the graphs haven't a external defined colour. * include/graphs/fgraph.php: changed for pass the data to static image graph generator. * operation/agentes/graphs.php: changed to use the new graph engine. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4172 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
18c1ef9163
commit
c4a0573398
|
@ -1,3 +1,22 @@
|
|||
2011-04-05 Miguel de Dios <miguel.dedios@artica.es>
|
||||
* include/functions_fsgraph.php, include/functions_graph.php,
|
||||
include/graphs/functions_utils.php, include/fgraph.php: cleaned source code
|
||||
style.
|
||||
|
||||
* include/functions_graph.php: added first version of function
|
||||
"graphic_combined_module2".
|
||||
|
||||
* include/graphs/functions_pchart.php: fixed when pass a empty array as
|
||||
colour for graphs.
|
||||
|
||||
* include/graphs/pChart/pDraw.class.php: fixed to set a color border when
|
||||
the graphs haven't a external defined colour.
|
||||
|
||||
* include/graphs/fgraph.php: changed for pass the data to static image graph
|
||||
generator.
|
||||
|
||||
* operation/agentes/graphs.php: changed to use the new graph engine.
|
||||
|
||||
2011-04-04 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* operation/events/events_list.php, operation/events/events.php: fixed
|
||||
|
|
|
@ -135,7 +135,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
|
|||
$title, $unit_name, $show_events = 0, $show_alerts = 0, $pure = 0, $stacked = 0, $date = 0) {
|
||||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
|
||||
// Set variables
|
||||
if ($date == 0) $date = get_system_time();
|
||||
$datelimit = $date - $period;
|
||||
|
@ -336,9 +336,11 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $
|
|||
}
|
||||
|
||||
if (! $graphic_type) {
|
||||
///FLASH
|
||||
return fs_combined_chart ($graph_values, $graph, $module_name_list, $width, $height, $stacked, $resolution / 10, $time_format);
|
||||
}
|
||||
|
||||
|
||||
//IMAGE
|
||||
$engine = get_graph_engine ($period);
|
||||
|
||||
$engine->width = $width;
|
||||
|
@ -1865,6 +1867,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ function fs_combined_chart ($data, $categories, $sets, $width, $height, $type =
|
|||
if (sizeof ($data) == 0) {
|
||||
return fs_error_image ();
|
||||
}
|
||||
|
||||
|
||||
// Generate the XML
|
||||
switch ($type) {
|
||||
case 0: $chart_type = 'MSArea2D';
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
// GNU General Public License for more details.
|
||||
|
||||
include_once($config["homedir"] . "/include/graphs/fgraph.php");
|
||||
include_once($config["homedir"] . "/include/functions_reporting.php");
|
||||
|
||||
function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events,
|
||||
$width, $height , $title, $unit_name,
|
||||
|
@ -283,8 +284,276 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events,
|
|||
$legend['max'] = __('Max') . ' (' . $max_value . ')';
|
||||
$legend['min'] = __('Min') . ' (' . $min_value . ')';
|
||||
$legend['baseline'] = __('Baseline');
|
||||
//$legend = null;
|
||||
|
||||
area_graph(0, $chart, $width, $height, $avg_only, $resolution / 10, $time_format, $show_events, $show_alerts, $caption, $baseline, $color, $legend, $long_index);
|
||||
return area_graph($config['flash_charts'], $chart, $width, $height, $color,$legend, $long_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a combined/user defined graph
|
||||
*
|
||||
* @param array List of source modules
|
||||
* @param array List of weighs for each module
|
||||
* @param int Period (in seconds)
|
||||
* @param int Width, in pixels
|
||||
* @param int Height, in pixels
|
||||
* @param string Title for graph
|
||||
* @param string Unit name, for render in legend
|
||||
* @param int Show events in graph (set to 1)
|
||||
* @param int Show alerts in graph (set to 1)
|
||||
* @param int Pure mode (without titles) (set to 1)
|
||||
* @param int Date to start of getting info.
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
function graphic_combined_module2 ($module_list, $weight_list, $period, $width, $height,
|
||||
$title, $unit_name, $show_events = 0, $show_alerts = 0, $pure = 0, $stacked = 0, $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);
|
||||
$module_number = count ($module_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
|
||||
|
||||
// Init weights
|
||||
for ($i = 0; $i < $module_number; $i++) {
|
||||
if (! isset ($weight_list[$i])) {
|
||||
$weight_list[$i] = 1;
|
||||
} else if ($weight_list[$i] == 0) {
|
||||
$weight_list[$i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set data containers
|
||||
for ($i = 0; $i < $resolution; $i++) {
|
||||
$timestamp = $datelimit + ($interval * $i);
|
||||
|
||||
$graph[$timestamp]['count'] = 0;
|
||||
$graph[$timestamp]['timestamp_bottom'] = $timestamp;
|
||||
$graph[$timestamp]['timestamp_top'] = $timestamp + $interval;
|
||||
$graph[$timestamp]['min'] = 0;
|
||||
$graph[$timestamp]['max'] = 0;
|
||||
$graph[$timestamp]['event'] = 0;
|
||||
$graph[$timestamp]['alert'] = 0;
|
||||
}
|
||||
|
||||
// Calculate data for each module
|
||||
for ($i = 0; $i < $module_number; $i++) {
|
||||
|
||||
$agent_module_id = $module_list[$i];
|
||||
$agent_name = get_agentmodule_agent_name ($agent_module_id);
|
||||
$agent_id = get_agent_id ($agent_name);
|
||||
$module_name = get_agentmodule_name ($agent_module_id);
|
||||
$module_name_list[$i] = $agent_name." / ".substr ($module_name, 0, 40);
|
||||
$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;
|
||||
}
|
||||
|
||||
// Set initial conditions
|
||||
$graph_values[$i] = array();
|
||||
|
||||
// Check available data
|
||||
if (count ($data) < $min_necessary) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Data iterator
|
||||
$j = 0;
|
||||
|
||||
// Event iterator
|
||||
$k = 0;
|
||||
|
||||
// Set initial conditions
|
||||
$graph_values[$i] = array();
|
||||
if ($data[0]['utimestamp'] == $datelimit) {
|
||||
$previous_data = $data[0]['datos'];
|
||||
$j++;
|
||||
} else {
|
||||
$previous_data = 0;
|
||||
}
|
||||
|
||||
// Calculate chart data
|
||||
for ($l = 0; $l < $resolution; $l++) {
|
||||
$timestamp = $datelimit + ($interval * $l);
|
||||
|
||||
$total = 0;
|
||||
$count = 0;
|
||||
|
||||
// Read data that falls in the current interval
|
||||
$interval_min = $previous_data;
|
||||
$interval_max = $previous_data;
|
||||
while (isset ($data[$j]) && $data[$j]['utimestamp'] >= $timestamp && $data[$j]['utimestamp'] < ($timestamp + $interval)) {
|
||||
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++;
|
||||
}
|
||||
|
||||
// Average
|
||||
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) {
|
||||
$graph_values[$i][$timestamp] = $total * $weight_list[$i];
|
||||
$previous_data = $total;
|
||||
// Compressed data
|
||||
} else {
|
||||
if ($uncompressed_module || ($timestamp > time ())) {
|
||||
$graph_values[$i][$timestamp] = 0;
|
||||
} else {
|
||||
$graph_values[$i][$timestamp] = $previous_data * $weight_list[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $module_number; $i++) {
|
||||
if ($weight_list[$i] != 1)
|
||||
$module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")";
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
switch ($stacked) {
|
||||
case 0:
|
||||
return area_graph($config['flash_charts'], $graph_values, $width, $height,
|
||||
$color, $legend, $long_index);
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
//TODO
|
||||
$chart_type = 'StackedArea2D';
|
||||
break;
|
||||
case 2:
|
||||
$chart_type = 'MSLine';
|
||||
//TODO
|
||||
break;
|
||||
case 3:
|
||||
$chart_type = 'MSLine';
|
||||
//TODO
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
if (! $graphic_type) {
|
||||
return fs_combined_chart ($graph_values, $graph, $module_name_list, $width, $height, $stacked, $resolution / 10, $time_format);
|
||||
}
|
||||
|
||||
$engine = get_graph_engine ($period);
|
||||
|
||||
$engine->width = $width;
|
||||
$engine->height = $height;
|
||||
$engine->data = &$graph_values;
|
||||
$engine->legend = $module_name_list;
|
||||
$engine->fontpath = $config['fontpath'];
|
||||
$engine->title = "";
|
||||
$engine->subtitle = "";
|
||||
$engine->show_title = !$pure;
|
||||
$engine->stacked = $stacked;
|
||||
$engine->xaxis_interval = $resolution;
|
||||
$events = false;
|
||||
$alerts = false;
|
||||
if (!isset($max_value)) {
|
||||
$max_value = 0;
|
||||
}
|
||||
|
||||
$engine->combined_graph ($graph, $events, $alerts, $unit_name, $max_value, $stacked);
|
||||
}
|
||||
?>
|
|
@ -42,13 +42,14 @@ function threshold_graph($flash_chart, $chart_data, $width, $height) {
|
|||
}
|
||||
}
|
||||
|
||||
function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend, $long_index) {
|
||||
function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend, $long_index) {
|
||||
if($flash_chart) {
|
||||
echo fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index);
|
||||
return fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index);
|
||||
}
|
||||
else {
|
||||
$id_graph = uniqid();
|
||||
|
||||
|
||||
$graph = array();
|
||||
$graph['data'] = $chart_data;
|
||||
$graph['width'] = $width;
|
||||
|
@ -56,12 +57,10 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend,
|
|||
$graph['color'] = $color;
|
||||
$graph['legend'] = $legend;
|
||||
|
||||
session_start();
|
||||
//unset($_SESSION['graph']);
|
||||
$_SESSION['graph_session'][$id_graph] = $graph;
|
||||
serialize_in_temp($graph, $id_graph);
|
||||
session_write_close();
|
||||
|
||||
echo "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "'>";
|
||||
return "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "'>";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c
|
|||
}
|
||||
|
||||
$MyData->addPoints($values,$point_id);
|
||||
if($rgb_color !== false) {
|
||||
if (!empty($rgb_color)) {
|
||||
$MyData->setPalette($point_id,
|
||||
array("R" => $rgb_color[$i]['color']["R"],
|
||||
"G" => $rgb_color[$i]['color']["G"],
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
function serialize_in_temp($array = array(), $serial_id = null) {
|
||||
$json = json_encode($array);
|
||||
|
||||
if($serial_id === null) {
|
||||
if ($serial_id === null) {
|
||||
$serial_id = uniqid();
|
||||
}
|
||||
|
||||
$file_path = sys_get_temp_dir()."/pandora_serialize_".$serial_id;
|
||||
|
||||
if(file_put_contents($file_path, $json) === false) {
|
||||
if (file_put_contents($file_path, $json) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ function serialize_in_temp($array = array(), $serial_id = null) {
|
|||
}
|
||||
|
||||
function unserialize_in_temp($serial_id = null, $delete = true) {
|
||||
if($serial_id === null) {
|
||||
if ($serial_id === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,13 @@ function unserialize_in_temp($serial_id = null, $delete = true) {
|
|||
|
||||
$content = file_get_contents($file_path);
|
||||
|
||||
if($content === false) {
|
||||
if ($content === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$array = json_decode($content, true);
|
||||
|
||||
if($delete) {
|
||||
if ($delete) {
|
||||
unlink($file_path);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ function unserialize_in_temp($serial_id = null, $delete = true) {
|
|||
}
|
||||
|
||||
function delete_unserialize_in_temp($serial_id = null) {
|
||||
if($serial_id === null) {
|
||||
if ($serial_id === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3689,9 +3689,19 @@
|
|||
$R = $Serie["Color"]["R"];
|
||||
$G = $Serie["Color"]["G"];
|
||||
$B = $Serie["Color"]["B"];
|
||||
$BorderR = $Serie["Color"]["BorderR"];
|
||||
$BorderG = $Serie["Color"]["BorderG"];
|
||||
$BorderB = $Serie["Color"]["BorderB"];
|
||||
debugPrint($Serie["Color"], true);
|
||||
if (isset($Serie["Color"]["BorderR"]))
|
||||
$BorderR = $Serie["Color"]["BorderR"];
|
||||
else
|
||||
$BorderR = $R;
|
||||
if (isset($Serie["Color"]["BorderG"]))
|
||||
$BorderG = $Serie["Color"]["BorderG"];
|
||||
else
|
||||
$BorderG = $G;
|
||||
if (isset($Serie["Color"]["BorderB"]))
|
||||
$BorderB = $Serie["Color"]["BorderB"];
|
||||
else
|
||||
$BorderB = $B;
|
||||
$Alpha = $Serie["Color"]["Alpha"];
|
||||
$Ticks = $Serie["Ticks"];
|
||||
if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
|
||||
|
|
|
@ -25,7 +25,7 @@ if (! check_acl ($config['id_user'], $id_grupo, "AR")) {
|
|||
return;
|
||||
}
|
||||
|
||||
require_once('include/fgraph.php');
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
$period = get_parameter ( "period", 3600);
|
||||
$draw_alerts = get_parameter("draw_alerts", 0);
|
||||
|
@ -123,26 +123,8 @@ else
|
|||
|
||||
foreach ($modulesChecked as $idModuleShowGraph => $value) {
|
||||
echo "<h3>" . $modules[$idModuleShowGraph] . '</h3>';
|
||||
if ($config['flash_charts']) {
|
||||
echo grafico_modulo_sparse ($idModuleShowGraph, $period, $draw_events, $width, $height,
|
||||
$modules[$idModuleShowGraph], $unit_name, $draw_alerts, $avg_only, $pure, $date);
|
||||
}
|
||||
else {
|
||||
$image = 'include/fgraph.php?' .
|
||||
'tipo=sparse' .
|
||||
'&draw_alerts=' . $draw_alerts .
|
||||
'&draw_events=' . $draw_events .
|
||||
'&id=' . $idModuleShowGraph .
|
||||
'&zoom=' . $zoom .
|
||||
'&label=' . $modules[$idModuleShowGraph] .
|
||||
'&height=' . $height .
|
||||
'&width=' . $width .
|
||||
'&period=' . $period .
|
||||
'&avg_only=' . $avg_only .
|
||||
'&date=' . $date;
|
||||
|
||||
print_image ($image, false, array ("border" => 0));
|
||||
}
|
||||
echo grafico_modulo_sparse2($idModuleShowGraph, $period, $draw_events, $width, $height,
|
||||
$modules[$idModuleShowGraph], $unit_name, $draw_alerts, $avg_only, $pure, $date);
|
||||
}
|
||||
|
||||
echo "<div style='clear: both;'></div>";
|
||||
|
|
Loading…
Reference in New Issue