A reporting/old_jpg_functions

A    reporting/old_jpg_functions/fgraph.php
A    reporting/old_jpg_functions/stat_win.php
M    reporting/fgraph.php


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@84 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
dervitx 2006-07-04 16:01:36 +00:00
parent 54a0db6509
commit f78dd46a7b
3 changed files with 1539 additions and 64 deletions

View File

@ -5,6 +5,7 @@
// Este codigo esta protegido por la licencia GPL.
// Sancho Lerena <slerena@gmail.com>, 2003-2006
// Raúl Mateos <raulofpandora@gmail.com>, 2006
// Jose Navarro <contacto@indiseg.net>, 2006
// Load global vars
include ("../include/config.php");
@ -35,16 +36,23 @@ function dame_fecha_grafico($mh){ // Devuelve fecha formateada en funcion de un
return $m;
}
function grafico_modulo_sparse($id_agente_modulo, $periodo, $intervalo, $etiqueta, $color){
function dame_fecha_grafico_timestamp ($timestamp) { return date('d/m H:i', $timestamp); }
function grafico_modulo_sparse($id_agente_modulo, $periodo, $intervalo, $etiqueta, $color, $draw_events=0){
include ("../include/config.php");
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_line.php");
include ("jpgraph/jpgraph_scatter.php");
require ("../include/languages/language_".$language_code.".php");
// WHere periodo is lapse of time in seconds that we want to show in a graph, this could be a week, 1 hour, a day, etc
// WHere periodo is lapse of time in minutes that we want to show in a graph, this could be a week, 1 hour, a day, etc
// 30.06.06 dervitx
// $draw_events behaves as a boolean: 1 implies that events for that module in that period of time
// will be represented with a line in the graph
$fechatope = dame_fecha($periodo); // Max old-date limit
$horasint = $periodo / $intervalo; // Each intervalo is $horasint seconds length
$nombre_agente = dame_nombre_agente_agentemodulo($id_agente_modulo);
$id_agente = dame_agente_id($nombre_agente);
$nombre_modulo = dame_nombre_modulo_agentemodulo($id_agente_modulo);
// Para crear las graficas vamos a crear un array de Ax4 elementos, donde
@ -193,74 +201,127 @@ function grafico_modulo_sparse($id_agente_modulo, $periodo, $intervalo, $etiquet
$etiq_base = $etiq_base2;
}
// Create graph
$graph = new Graph(550,220);
$graph->SetMargin(50,120,30,60);
$valor_maximo = ceil($valor_maximo / 4) + $valor_maximo;
$graph->SetScale("textlin",0,$valor_maximo,0,0);
$graph->SetAlphaBlending();
// Which background color
$graph->SetMarginColor('white');
// Without frame
$graph->SetFrame(false);
// Colour Y-axe line
$graph->ygrid->SetFill(true,'#EFEFEF@0.6','#BBCCFF@0.6');
//$graph->xgrid->Show();
// Title
$graph->tabtitle->Set("$etiqueta - $nombre_agente / $nombre_modulo");
// To use true type fonts (who permits a label text in angle of 45)
// cp /usr/share/fonts/truetype/msttcorefonts/arial.ttf /usr/X11R6/lib/X11/fonts/truetype/
if ($config_truetype == 1){
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,7);
$graph->xaxis->SetLabelAngle(35);
} else {
// Fixed font
$graph->xaxis->SetFont(FF_FONT0);
$graph->xaxis->SetLabelAngle(90);
// 29.06.06 dervitx
// let's see if the module in this agent has some events associated
// if it has, let's fill $datax and $datay to scatter the events
// in the graphic
if ($draw_events) {
$initial_time = strtotime($fechatope);
$graph_duration = $periodo * 60; // in seconds
$final_time = $initial_time + $graph_duration; // now
// careful here! next sql sentence looks for the module by name in the "evento" field
// tevento database table SHOULD have module_id !!
$sql1 = "SELECT * FROM tevento WHERE id_agente = ".$id_agente." and timestamp > '".$fechatope."' and evento like '%" . $nombre_modulo . "%' ";
// we populate two arrays with validated and no validated events of the module:
// $datax[1] and $datax[0], respectively. There are $datay arrays for y values.
if ($result=mysql_query($sql1)){
while ($row=mysql_fetch_array($result)) {
if ($row["estado"]) { $estado=1; } else { $estado=0; }
$datax[$estado][count($datax[$estado])] = strtotime( $row["timestamp"] );
$datay[$estado][count($datay[$estado])] = ceil($valor_maximo / 6) + $valor_maximo;
}
}
}
// end 29.06.06 dervitx
$graph->xaxis->SetTickLabels($etiq_base);
//$graph->xaxis->SetTextLabelInterval(ceil($intervalo / 10),0);
$graph->xaxis->SetTextTickInterval(ceil($intervalo/10),0);
$graph->yaxis->SetFont(FF_FONT0);
// Crete data line
// 30.06.06 dervitx
// creating the graph with PEAR Image_Graph
include 'Image/Graph.php';
$Graph =& Image_Graph::factory('graph', array(550, 220));
$Font =& $Graph->addNew('font', $config_fontpath);
$Font->setSize(8);
$Graph->setFont($Font);
$Graph->add(
Image_Graph::vertical(
$Title = Image_Graph::factory('title', array(" $etiqueta - $nombre_agente / $nombre_modulo", 10)),
Image_Graph::horizontal(
$Plotarea = Image_Graph::factory('plotarea','axis'),
$Legend = Image_Graph::factory('legend'),
80
),
5
)
);
$line0=new LinePlot($valores_max);
$line0->SetColor("blue");
$line0->SetWeight(1);
$line0->SetFillColor("blue@0.2");
$line0->SetLegend($lang_label["max"]);
$Title->setAlignment(IMAGE_GRAPH_ALIGN_LEFT);
$line1=new LinePlot($grafica);
$line1->SetColor($color);
$line1->SetWeight(1);
$line1->SetFillColor($color."@0.2");
$line1->SetLegend($lang_label["med"]);
$Grid =& $Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_X);
$Grid->setBackgroundColor('silver@0.3');
$Grid->setBorderColor('black');
$Plotarea->addNew('line_grid', false, IMAGE_GRAPH_AXIS_Y);
// the next grid is only necessary for drawing the right black line of the PlotArea
$Grid_sec =& $Plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y_SECONDARY);
$Grid_sec->setBorderColor('black');
$line2=new LinePlot($valores_min);
$line2->SetColor("yellow");
$line2->SetWeight(1);
$line2->SetFillColor("yellow@0.2");
$line2->SetLegend($lang_label["min"]);
// now, datasets are created ...
$Datasets = array (
Image_Graph::factory('dataset'),
Image_Graph::factory('dataset'),
Image_Graph::factory('dataset'),
);
$Datasets[0]->setName('Average');
$Datasets[1]->setName('Maximum');
$Datasets[2]->setName('Minimum');
$Legend->setPlotarea($Plotarea);
// Add line to graph
$graph->Add($line0);
$graph->Add($line1);
$graph->Add($line2);
// ... and populated with data ...
for ($cc=0; $cc<count($grafica); $cc++) {
$tdate=strtotime($etiq_base[$cc]);
$Datasets[0]->addPoint($tdate,$grafica[$cc]);
$Datasets[1]->addPoint($tdate,$valores_max[$cc]);
$Datasets[2]->addPoint($tdate,$valores_min[$cc]);
}
$graph->legend->Pos(0.01,0.2,"right","center");
// ... and added to the Graph
$Plot =& $Plotarea->addNew('Image_Graph_Plot_Area', array($Datasets));
// Y-axe up graph
$graph->SetGridDepth(DEPTH_BACK);
// Antialias
// $graph->img->SetAntiAliasing();
// Mostramos la imagen
$graph->Stroke();
// some other properties of the Graph
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$FillArray->addColor('orange');
$FillArray->addColor('blue');
$FillArray->addColor('yellow');
$Plot->setFillStyle($FillArray);
$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
$AxisX->setLabelInterval($periodo*60/10);
$AxisX->setFontAngle(45);
$AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'dame_fecha_grafico_timestamp'));
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
$AxisY->forceMaximum(ceil($valor_maximo / 4) + $valor_maximo);
// let's draw the alerts zones
$sql1 = "SELECT dis_min, dis_max FROM talerta_agente_modulo WHERE id_agente_modulo = ".$id_agente_modulo;
if ($result=mysql_query($sql1)){
while ($row=mysql_fetch_array($result)) {
$Marker_alertzone =& $Plotarea->addNew('Image_Graph_Axis_Marker_Area', IMAGE_GRAPH_AXIS_Y);
$Marker_alertzone->setFillColor('green@0.2');
$Marker_alertzone->setLowerBound($row["dis_min"]);
$Marker_alertzone->setUpperBound($row["dis_max"]);
}
}
// if there are some events to draw let's scatter them!
if ($draw_events) {
for ($cc=1; $cc>=0; $cc--) {
if (isset($datay[$cc])) {
$Dataset_events =& Image_Graph::factory('dataset');
$Dataset_events->setName($cc?'Validated events':'Not valid. events');
for ($nn=0; $nn<count($datax[$cc]); $nn++) {
$Dataset_events->addPoint($datax[$cc][$nn], $datay[$cc][$nn]);
}
$Plot =& $Plotarea->addNew('Plot_Impulse', array(&$Dataset_events));
$Plot->setLineColor($cc?'green@0.5':'red@0.5');
$Marker_event =& Image_Graph::factory('Image_Graph_Marker_Diamond');
$Plot->setMarker($Marker_event);
$Marker_event->setFillColor($cc?'green@0.5':'red@0.5');
$Marker_event->setLineColor('black');
}
}
}
$Graph->done();
// 30.06.06 dervitx end
}
function graphic_agentmodules($id_agent) {
@ -1297,7 +1358,9 @@ if (isset($_GET["tipo"])){
$intervalo = $_GET["intervalo"];
$label = $_GET["label"];
$color = "#".$color;
grafico_modulo_sparse($id, $periodo, $intervalo, $label, $color);
if ( isset($_GET["draw_events"]) and $_GET["draw_events"]==1 )
{ $draw_events = 1; } else { $draw_events = 0; }
grafico_modulo_sparse($id, $periodo, $intervalo, $label, $color, $draw_events);
}
}
elseif ($_GET["tipo"] =="estado_incidente")
@ -1335,4 +1398,4 @@ if (isset($_GET["tipo"])){
progress_bar($percent,$width,$height);
}
}
?>
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
<?php
// Pandora - The Free Monitoring System
// This code is protected by GPL license.
// Este codigo esta protegido por la licencia GPL.
// Sancho Lerena <slerena@gmail.com>, 2003-2006
// Cargamos variables globales
session_start();
include ("../include/config.php");
include ("../include/functions.php");
include("../include/functions_db.php");
include("../include/languages/language_".$language_code.".php");
echo '<style>';
include("../include/styles/pandora.css");
echo '</style>';
if (comprueba_login() == 0) {
// Has access to this page ???
if (isset($_GET["tipo"]) AND isset($_GET["id"])) {
$tipo =entrada_limpia($_GET["tipo"]);
$id_agente_modulo = entrada_limpia($_GET["id"]);
}
else {
echo "<h3 class='error'>".$lang_label["graf_error"]."</h3>";
exit;
}
// Nota: En los intervalos, se han aumentado por encima de los 24 del grafico diario y los 7 del semanal para
// que la grafica tenga mas resolucion. Cuanto mayor sea el intervalo mas tardara la grafica en generarse !!!.
// TODO: Crear una variable para que se pueda utilizar como factor de resolucion de graficos y parametrizarlo en un
// archivo de configuracion.
$module_interval = give_moduleinterval($id_agente_modulo);
// Interval defined for this module or agent general interval, if interval for this specific module not defined
$module_interval = $module_interval / 60; // Convert to resol / minute
// Please be caution, interval now is in MINUTES not in seconds
// interval is the number of rows that will store data. more rows, more resolution
switch ($tipo) {
case "mes": $intervalo = 30 * $config_graph_res;
$intervalo_real = (43200 / $module_interval);
if ($intervalo_real < $intervalo ){
$intervalo = $intervalo_real;
}
echo "<img src='fgraph.php?id=".$id_agente_modulo."&color=6e90ff&tipo=sparse&periodo=43200&intervalo=".$intervalo."&label=".$lang_label["month_graph"]."' border=0>";
break;
case "dia": $intervalo = 24 * $config_graph_res;
$intervalo_real = (1440 / $module_interval);
if ($intervalo_real < $intervalo ){
$intervalo = $intervalo_real;
}
echo "<img src='fgraph.php?id=".$id_agente_modulo."&color=f3c330&tipo=sparse&periodo=1440&intervalo=".$intervalo."&label=".$lang_label["day_graph"]."' border=0 alt=''>";
break;
case "semana": $intervalo = 28 * $config_graph_res;
$intervalo_real = (10080 / $module_interval);
if ($intervalo_real < $intervalo ) {
$intervalo = $intervalo_real;
}
echo "<img src='fgraph.php?id=".$id_agente_modulo."&color=e366cd&tipo=sparse&periodo=10080&intervalo=".$intervalo."&label=".$lang_label["week_graph"]."' border=0 alt=''>";
break;
case "hora": $intervalo = 5 * $config_graph_res;
$intervalo_real = 60 / $module_interval;
if ($intervalo_real < $intervalo ) {
$intervalo = $intervalo_real;
}
// $intervalo=20;
echo "<img src='fgraph.php?id=".$id_agente_modulo."&color=40d840&tipo=sparse&periodo=60&intervalo=".$intervalo."&label=".$lang_label["hour_graph"]."' border=0 alt=''>";
break;
}
} // Fin pagina
?>