2009-04-06 Evi Vanoost <vanooste@rcbi.rochester.edu>

* reporting/fgraph.php: Simplified agent access to reduce looping
	
	* reporting/pChart/pChart.class: Found problem where the graph was
	looping with certain data when the Scale1 was exactly 1

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1599 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2009-04-06 15:33:08 +00:00
parent 2e566a1738
commit e615a6be89
3 changed files with 101 additions and 119 deletions

View File

@ -1,3 +1,10 @@
2009-04-06 Evi Vanoost <vanooste@rcbi.rochester.edu>
* reporting/fgraph.php: Simplified agent access to reduce looping
* reporting/pChart/pChart.class: Found problem where the graph was
looping with certain data when the Scale1 was exactly 1
2009-04-06 Sancho Lerena <slerena@artica.es>
* godmode/setup/setup.php

View File

@ -430,11 +430,8 @@ function graphic_agentmodules ($id_agent, $width, $height) {
function graphic_agentaccess ($id_agent, $width, $height, $period = 0) {
global $config;
/* BROKEN: Need to fix, it gets 100% CPU of Apache !!!*/
$data = array();
/*
$resolution = $config["graph_res"] * ($period * 2 / $width); // Number of "slices" we want in graph
$interval = (int) ($period / $resolution);
@ -443,52 +440,30 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0) {
$periodtime = floor ($period / $interval);
$time = array ();
$data = array ();
for ($i = 0; $i < $interval; $i++) {
$time[$i]['timestamp_bottom'] = $datelimit + ($periodtime * $i);
$time[$i]['timestamp_top'] = $datelimit + ($periodtime * ($i + 1));
$data[$time[$i]['timestamp_bottom']] = 0;
$bottom = $datelimit + ($periodtime * $i);
$top = $datelimit + ($periodtime * ($i + 1));
$data[$bottom] = (int) get_db_sql ("SELECT COUNT(*) FROM tagent_access WHERE
id_agent = ".$id_agent." AND
utimestamp > ".$bottom." AND
utimestamp < ".$top);
}
$result = get_db_all_rows_filter ('tagent_access',
array ('id_agent' => $id_agent,
"utimestamp > $datelimit",
"utimestamp < $date"),
array ('utimestamp'));
if ($result === false)
$result = array ();
// SEEMS that problem is below
// it get's 100% cpu on apache and problem is localed here, I don't exactly
// why or what is happening here, but i'm sure that the problem is here.
$max_value = 0;
foreach ($result as $access) {
$utimestamp = $access['utimestamp'];
for ($i = 0; $i < $interval; $i++) {
if ($utimestamp <= $time[$i]['timestamp_top'] && $utimestamp >= $time[$i]['timestamp_bottom']) {
$data[$time[$i]['timestamp_bottom']]++;
$max_value = max ($max_value, $data[$time[$i]['timestamp_bottom']]);
}
}
}
*/
$engine = get_graph_engine ($period);
$engine->width = $width;
$engine->height = $height;
$engine->data = &$data;
$engine->max_value = $max_value;
$engine->data = $data;
$engine->max_value = max ($data);
$engine->show_title = false;
$engine->fontpath = $config['fontpath'];
$engine->xaxis_interval = floor ($width / 72);
$engine->yaxis_interval = $max_value;
$engine->yaxis_interval = max ($data);
$engine->xaxis_format = 'date';
$engine->watermark = false;
$engine->show_grid = false;
$engine->single_graph ();
}

View File

@ -1,17 +1,17 @@
<?php
/*
Updated for Pandora on 2009-03-12. Changes:
- Added drawOverlayBarGraphH()
- Draw a single rectangle on drawRoundedRectangle() when the radius is 0.
<?php
/*
Updated for Pandora on 2009-03-12. Changes:
- Added drawOverlayBarGraphH()
- Draw a single rectangle on drawRoundedRectangle() when the radius is 0.
- Typo when calling $ko on ToMetric()
*/
/*
pChart - a PHP class to build charts!
Copyright (C) 2008 Jean-Damien POGOLOTTI
Version 1.27d last updated on 09/30/08
Version 1.27d last updated on 09/30/08
http://pchart.sourceforge.net
@ -693,8 +693,8 @@
$Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
$Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
if ( $Scale1 >= 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
if ( $Scale2 >= 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
if (!$ScaleOk)
{
if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
@ -950,8 +950,8 @@
$YPos = $YPos - $this->DivisionHeight;
}
/* Vertical lines */
if (!$DrawVerticals)
/* Vertical lines */
if (!$DrawVerticals)
return;
if ( $this->GAreaXOffset == 0 )
{ $XPos = $this->GArea_X1 + $this->DivisionWidth + $this->GAreaXOffset; $ColCount = $this->DataCount-2; }
@ -1078,70 +1078,70 @@
$ID++;
}
}
function drawOverlayBarGraphH($Data,$DataDescription,$Alpha=50)
{
/* Validate the Data and DataDescription array */
$this->validateDataDescription("drawOverlayBarGraphH",$DataDescription);
$this->validateData("drawOverlayBarGraphH",$Data);
$LayerWidth = $this->GArea_X2-$this->GArea_X1;
$LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
$GraphID = 0;
foreach ( $DataDescription["Values"] as $Key2 => $ColName )
{
$ID = 0;
foreach ( $DataDescription["Description"] as $keyI => $ValueI )
{
if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++;
}
$this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth,$LayerHeight);
$C_White = imagecolorallocate($this->Layers[$GraphID],255,255,255);
$C_Black = imagecolorallocate($this->Layers[$GraphID],0,0,0);
$C_Graph = imagecolorallocate($this->Layers[$GraphID],$this->Palette[$GraphID]["R"],$this->Palette[$GraphID]["G"],$this->Palette[$GraphID]["B"]);
imagefilledrectangle($this->Layers[$GraphID],0,0,$LayerWidth,$LayerHeight,$C_White);
imagecolortransparent($this->Layers[$GraphID],$C_White);
$XWidth = $this->DivisionWidth / 4;
$XPos = $this->GAreaXOffset;
$YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
$XLast = -1; $PointsCount = 2;
$XZero = 0;
$YPad = 20; //$LayerHeight / count($Data);
$YHeight = 8;
$YPos = $YHeight;
$Divisi = ($LayerWidth / ($this->VMax - $this->VMin));
foreach ( $Data as $Key => $Values )
{
if ( isset($Data[$Key][$ColName]) )
{
$Value = $Data[$Key][$ColName];
$XPos = (($Value-$this->VMin) * $Divisi) ;
imagefilledrectangle($this->Layers[$GraphID],$XPos,$YPos+$YHeight,$XZero,$YPos-$YHeight,$C_Graph);
imagettftext($this->Layers[$GraphID],$this->FontSize,0,$XZero+2,$YPos+4,$C_Black,$this->FontName, $Data[$Key][$DataDescription["Position"]]." (".round($Value,2).")");
$X1 = floor($XPos - $XWidth + $this->GArea_X1); $Y1 = floor($YPos+$this->GArea_Y1) + .2;
$X2 = floor($XPos + $XWidth + $this->GArea_X1);
if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
if ( $this->BuildMap )
$this->addToImageMap($X1,min($Y1,$Y2),$X2,max($Y1,$Y2),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"oBar");
$this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
}
$YPos= $YPos + $YPad;
}
$GraphID++;
}
for($i=0;$i<=($GraphID-1);$i++)
{
imagecopymerge($this->Picture,$this->Layers[$i],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
imagedestroy($this->Layers[$i]);
}
function drawOverlayBarGraphH($Data,$DataDescription,$Alpha=50)
{
/* Validate the Data and DataDescription array */
$this->validateDataDescription("drawOverlayBarGraphH",$DataDescription);
$this->validateData("drawOverlayBarGraphH",$Data);
$LayerWidth = $this->GArea_X2-$this->GArea_X1;
$LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
$GraphID = 0;
foreach ( $DataDescription["Values"] as $Key2 => $ColName )
{
$ID = 0;
foreach ( $DataDescription["Description"] as $keyI => $ValueI )
{
if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++;
}
$this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth,$LayerHeight);
$C_White = imagecolorallocate($this->Layers[$GraphID],255,255,255);
$C_Black = imagecolorallocate($this->Layers[$GraphID],0,0,0);
$C_Graph = imagecolorallocate($this->Layers[$GraphID],$this->Palette[$GraphID]["R"],$this->Palette[$GraphID]["G"],$this->Palette[$GraphID]["B"]);
imagefilledrectangle($this->Layers[$GraphID],0,0,$LayerWidth,$LayerHeight,$C_White);
imagecolortransparent($this->Layers[$GraphID],$C_White);
$XWidth = $this->DivisionWidth / 4;
$XPos = $this->GAreaXOffset;
$YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
$XLast = -1; $PointsCount = 2;
$XZero = 0;
$YPad = 20; //$LayerHeight / count($Data);
$YHeight = 8;
$YPos = $YHeight;
$Divisi = ($LayerWidth / ($this->VMax - $this->VMin));
foreach ( $Data as $Key => $Values )
{
if ( isset($Data[$Key][$ColName]) )
{
$Value = $Data[$Key][$ColName];
$XPos = (($Value-$this->VMin) * $Divisi) ;
imagefilledrectangle($this->Layers[$GraphID],$XPos,$YPos+$YHeight,$XZero,$YPos-$YHeight,$C_Graph);
imagettftext($this->Layers[$GraphID],$this->FontSize,0,$XZero+2,$YPos+4,$C_Black,$this->FontName, $Data[$Key][$DataDescription["Position"]]." (".round($Value,2).")");
$X1 = floor($XPos - $XWidth + $this->GArea_X1); $Y1 = floor($YPos+$this->GArea_Y1) + .2;
$X2 = floor($XPos + $XWidth + $this->GArea_X1);
if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
if ( $this->BuildMap )
$this->addToImageMap($X1,min($Y1,$Y2),$X2,max($Y1,$Y2),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"oBar");
$this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
}
$YPos= $YPos + $YPad;
}
$GraphID++;
}
for($i=0;$i<=($GraphID-1);$i++)
{
imagecopymerge($this->Picture,$this->Layers[$i],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
imagedestroy($this->Layers[$i]);
}
}
/* Draw the graph title */
function drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
@ -2949,9 +2949,9 @@
{
if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( $Radius == 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B); return; }
if ( $Radius == 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B); return; }
$C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
@ -2990,7 +2990,7 @@
if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
if ( $Radius == 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B); return; }
$C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
@ -3563,6 +3563,6 @@
{
echo "[FATAL] ".$Message."\r\n";
exit();
}
}
?>
?>