diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2003-08-03 09:03:29 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2003-08-03 09:03:29 +0000 |
| commit | 6822f3a55614b2c2ed10479e63f6c39526b08708 (patch) | |
| tree | a7277df979428a462ace9f8c223f7b4798ae413a /frontends/php/include/classes.inc.php | |
| parent | 1a7b74a3fc4ea2b0264eb620e44654eeb3e6c081 (diff) | |
Minor changes (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@882 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/classes.inc.php')
| -rw-r--r-- | frontends/php/include/classes.inc.php | 637 |
1 files changed, 212 insertions, 425 deletions
diff --git a/frontends/php/include/classes.inc.php b/frontends/php/include/classes.inc.php index 56af249a..de273016 100644 --- a/frontends/php/include/classes.inc.php +++ b/frontends/php/include/classes.inc.php @@ -1,16 +1,51 @@ <?php +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003 Alexei Vladishev +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php class Graph { var $period; var $from; var $sizeX; var $sizeY; - var $itemid; var $shiftX; var $shiftY; var $border; - var $item; + // items[num].data.min[max|avg] + var $items; + // $idnum[$num] is itemid + var $itemids; + var $min; + var $max; + var $avg; + var $count; + // Number of items + var $num; + // 1 - if thereis nothing to draw + var $nodata; + + var $header; + + var $from_time; + var $to_time; var $colors; var $im; @@ -23,6 +58,7 @@ $this->colors["Green"]=ImageColorAllocate($this->im,0,255,0); $this->colors["Dark Green"]=ImageColorAllocate($this->im,0,150,0); $this->colors["Blue"]=ImageColorAllocate($this->im,0,0,255); + $this->colors["Dark Blue"]=ImageColorAllocate($this->im,0,0,150); $this->colors["Yellow"]=ImageColorAllocate($this->im,255,255,0); $this->colors["Dark Yellow"]=ImageColorAllocate($this->im,150,150,0); $this->colors["Cyan"]=ImageColorAllocate($this->im,0,255,255); @@ -31,7 +67,7 @@ $this->colors["White"]=ImageColorAllocate($this->im,255,255,255); } - function Graph($itemid) + function Graph() { $this->period=3600; $this->from=0; @@ -40,11 +76,17 @@ $this->shiftX=10; $this->shiftY=17; $this->border=1; - $this->itemid=$itemid; + $this->num=0; + $this->nodata=1; + + $this->count=array(); + for($i=0;$i<900;$i++) $count[$i]=0; + $this->min=array(); + $this->max=array(); + $this->avg=array(); + + $this->itemids=array(); - $this->item=get_item_by_itemid($this->itemid); - $host=get_host_by_hostid($this->item["hostid"]); - $this->item["host"]=$host["host"]; if($this->period<=3600) { @@ -56,6 +98,21 @@ } } + function addItem($itemid) + { + $this->items[$this->num]=get_item_by_itemid($itemid); + $host=get_host_by_hostid($this->items[$this->num]["hostid"]); + $this->items[$this->num]["host"]=$host["host"]; + $this->itemids[$this->items[$this->num]["itemid"]]=$this->num; + $this->items[$this->num]["color"]="Dark Green"; + $this->items[$this->num]["drawtype"]=GRAPH_DRAW_TYPE_LINE; + $this->num++; + } + + function SetColor($itemid,$color) + { + $this->items[$this->itemids[$itemid]]["color"]=$color; + } function setPeriod($period) { @@ -97,341 +154,156 @@ function drawHeader() { - $str=$this->item["host"].":".$this->item["description"]; + if(!isset($this->header)) + { + $str=$this->items[0]["host"].":".$this->items[0]["description"]; + } + else + { + $str=$this->header; + } $x=imagesx($this->im)/2-ImageFontWidth(4)*strlen($str)/2; ImageString($this->im, 4,$x,1, $str , $this->colors["Dark Red"]); } - function noDataFound() - { - ImageString($this->im, 2,$this->sizeX/2-50, $this->sizeY+$this->shiftY+3, "NO DATA FOUND FOR THIS PERIOD" , $this->colors["Dark Red"]); - ImageStringUp($this->im,0,imagesx($this->im)-10,imagesy($this->im)-50, "http://zabbix.sourceforge.net", $this->colors["Gray"]); - ImagePng($this->im); - ImageDestroy($this->im); - } - - function drawLogo() + function setHeader($header) { - ImageStringUp($this->im,0,imagesx($this->im)-10,imagesy($this->im)-50, "http://zabbix.sourceforge.net", $this->colors["Gray"]); + $this->header=$header; } - function Draw() + function drawGrid() { - $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40); - $nodata=1; - -// Header( "Content-type: text/html"); - Header( "Content-type: image/png"); - Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); - - check_authorisation(); - - $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40); - - $this->initColors(); - $this->drawRectangle(); - $this->drawHeader(); - - if(!check_right("Item","R",$this->itemid)) - { - ImagePng($this->im); - ImageDestroy($this->im); - exit; - } - - $from_time = time(NULL)-$this->period-3600*$this->from; - $to_time = time(NULL)-3600*$this->from; - $result=DBselect("select count(clock),min(clock),max(clock),min(value),max(value) from history where itemid=".$this->itemid." and clock>$from_time and clock<$to_time "); - $count=DBget_field($result,0,0); - if($count>0) - { - $nodata=0; - $minX=DBget_field($result,0,1); - $maxX=DBget_field($result,0,2); - $minY=DBget_field($result,0,3); - $maxY=DBget_field($result,0,4); - - } - else - { - $this->noDataFound(); - exit; - } - - $my_exp = floor(log10($maxY)); - $my_mant = $maxY/pow(10,$my_exp); - - if ($my_mant < 1.5 ) - { - $my_mant = 1.5; - $my_steps = 5; - } - elseif($my_mant < 2 ) - { - $my_mant = 2; - $my_steps = 4; - } - elseif($my_mant < 3 ) - { - $my_mant = 3; - $my_steps = 6; - } - elseif($my_mant < 5 ) - { - $my_mant = 5; - $my_steps = 5; - } - elseif($my_mant < 8 ) - { - $my_mant = 8; - $my_steps = 4; - } - else - { - $my_mant = 10; - $my_steps = 5; - } - $maxY = $my_mant*pow(10,$my_exp); - $minY = 0; - -// echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>"; - - if(isset($minX)&&($minX!=$maxX)&&($minY!=$maxY)) - { - $result=DBselect("select clock,value from history where itemid=".$this->itemid." and clock>$from_time and clock<$to_time order by clock"); - for($i=0;$i<DBnum_rows($result)-1;$i++) - { - $x=DBget_field($result,$i,0); - $x_next=DBget_field($result,$i+1,0); - $y=DBget_field($result,$i,1); - $y_next=DBget_field($result,$i+1,1); - - $x1=$this->sizeX*($x-$minX)/($maxX-$minX); - $y1=$this->sizeY*($y-$minY)/($maxY-$minY); - $x2=$this->sizeX*($x_next-$minX)/($maxX-$minX); - $y2=$this->sizeY*($y_next-$minY)/($maxY-$minY); - - $y1=$this->sizeY-$y1; - $y2=$this->sizeY-$y2; - - ImageLine($this->im,$x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY,$this->colors["Dark Green"]); -// ImageSetPixel($this->im,$x2+$this->shiftX,$y2+$this->shiftY-1,$this->colors["Dark Red"]); - } - } - else - { - if(isset($minX)) - { - ImageLine($this->im,$this->shiftX,$this->shiftY+$this->sizeY/2,$this->sizeX+$this->shiftX,$this->shiftY+$this->sizeY/2,$this->colors["Dark Green"]); - } - } - - $startTime=$minX; - if (($maxX-$minX) < 300) - $precTime=10; - elseif (($maxX-$minX) < 3600 ) - $precTime=60; - else - $precTime=300; - - if (($maxX-$minX) < 1200 ) - $dateForm="H:i:s"; - else - $dateForm="H:i:s"; - - $correctTime=$startTime % $precTime; - $stepTime=ceil(ceil(($maxX-$minX)/20)/$precTime)*(1.0*$precTime); - - for($i=1;$i<$my_steps;$i++) - { - ImageDashedLine($this->im,$this->shiftX,$i/$my_steps*$this->sizeY+$this->shiftY,$this->sizeX+$this->shiftX,$i/$my_steps*$this->sizeY+$this->shiftY,$this->colors["Gray"]); - } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) + for($i=0;$i<=$this->sizeY;$i+=$this->sizeY/6) { - ImageDashedLine($this->im,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->shiftY,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->sizeY+$this->shiftY,$this->colors["Gray"]); + ImageDashedLine($this->im,$this->shiftX,$i+$this->shiftY,$this->sizeX+$this->shiftX,$i+$this->shiftY,$this->colors["Gray"]); } - - if($nodata == 0) + for($i=0;$i<=$this->sizeX;$i+=$this->sizeX/24) { - for($i=0;$i<=$my_steps;$i++) - { - ImageString($this->im, 1, $this->sizeX+5+$this->shiftX, $i/$my_steps*$this->sizeY+$this->shiftY-4, convert_units($maxY-$i/$my_steps*($maxY-$minY),$this->item["units"],$this->item["multiplier"]) , $this->colors["Dark Red"]); - } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) + ImageDashedLine($this->im,$i+$this->shiftX,$this->shiftY,$i+$this->shiftX,$this->sizeY+$this->shiftY,$this->colors["Gray"]); + if($this->nodata == 0) { - ImageStringUp($this->im,0,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->shiftY+$this->sizeY+53,date($dateForm,$startTime+$j),$this->colors["Black"]); + ImageStringUp($this->im, 1,$i+$this->shiftX-3, $this->sizeY+$this->shiftY+29, date($this->date_format,$this->from_time+$i*$this->period/$this->sizeX) , $this->colors["Black"]); } - - ImageString($this->im, 1,10, $this->sizeY+$this->shiftY+5, date("dS of F Y H:i:s",$minX) , $this->colors["Dark Red"]); - ImageString($this->im, 1,$this->sizeX+$this->shiftX-148,$this->sizeY+$this->shiftY+5, date("dS of F Y H:i:s",$maxX) , $this->colors["Dark Red"]); } - else - { - ImageString($this->im, 2,$this->sizeX/2-50, $this->sizeY+$this->shiftY+3, "NO DATA FOUND FOR THIS PERIOD" , $this->colors["Dark Red"]); - } - - $this->drawLogo(); - - - ImagePng($this->im); - ImageDestroy($this->im); } - function Draw2() + function checkPermissions() { - $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40); - $nodata=1; - - Header( "Content-type: text/html"); -// Header( "Content-type: image/png"); - Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); - - check_authorisation(); - - $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40); - - $this->initColors(); - $this->drawRectangle(); - $this->drawHeader(); - - if(!check_right("Item","R",$this->itemid)) + if(!check_right("Item","R",$this->items[0]["itemid"])) { ImagePng($this->im); ImageDestroy($this->im); exit; } + } - $from_time = time(NULL)-$this->period-3600*$this->from; - $to_time = time(NULL)-3600*$this->from; + function noDataFound() + { + ImageString($this->im, 2,$this->sizeX/2-50, $this->sizeY+$this->shiftY+3, "NO DATA FOUND FOR THIS PERIOD" , $this->colors["Dark Red"]); + ImageStringUp($this->im,0,imagesx($this->im)-10,imagesy($this->im)-50, "http://zabbix.sourceforge.net", $this->colors["Gray"]); + ImagePng($this->im); + ImageDestroy($this->im); + } - for($i=0;$i<=$this->sizeX;$i+=$this->sizeX/24) - { -// ImageDashedLine($this->im,$i+$this->shiftX,$this->shiftY,$i+$this->shiftX,$this->sizeY+$this->shiftY,$this->colors["Gray"]); - $label_format="H:i"; - ImageString($this->im, 1,$i+$this->shiftX-11, $this->sizeY+$this->shiftY+5, date($label_format,$from_time+$this->period*($i/$this->sizeX)) , $this->colors["Black"]); - } + function drawLogo() + { + ImageStringUp($this->im,0,imagesx($this->im)-10,imagesy($this->im)-50, "http://zabbix.sourceforge.net", $this->colors["Gray"]); + } - $p=$to_time-$from_time; - $z=$from_time%$p; - $count=array(); - $min=array(); - $max=array(); - $avg=array(); + function drawLegend() + { + for($i=0;$i<$this->num;$i++) + { + } + + ImageFilledRectangle($this->im,$this->shiftX,$this->sizeY+$this->shiftY+35,$this->shiftX+5,$this->sizeY+$this->shiftY+5+35,$this->colors["Dark Green"]); + ImageRectangle($this->im,$this->shiftX,$this->sizeY+$this->shiftY+35,$this->shiftX+5,$this->sizeY+$this->shiftY+5+35,$this->colors["Black"]); + + $max_host_len=strlen($this->items[0]["host"]); + $max_desc_len=strlen($this->items[0]["description"]); +// for($i=0;$i<DBnum_rows($result2);$i++) +// { +// $z=get_item_by_itemid($iids[$i]); +// $h=get_host_by_hostid($z["hostid"]); +// if(strlen($h["host"])>$max_host_len) $max_host_len=strlen($h["host"]); +// if(strlen($z["description"])>$max_desc_len) $max_desc_len=strlen($z["description"]); +// } +// $i=get_item_by_itemid($iids[$item]); + $str=sprintf("%s: %s [min:%s max:%s]", + str_pad($this->items[0]["host"],$max_host_len," "), + str_pad($this->items[0]["description"],$max_desc_len," "), + convert_units(min($this->min[0]),$this->items[0]["units"],$this->items[0]["multiplier"]), + convert_units(max($this->max[0]),$this->items[0]["units"],$this->items[0]["multiplier"])); + + ImageString($this->im, 2,$this->shiftX+9,$this->sizeY+$this->shiftY+30,$str, $this->colors["Black"]); + } - $sql="select round(900*((clock+$z)%($p))/($p)) as i,count(*) as count,avg(value) as avg,min(value) as min,max(value) as max from history where itemid=".$this->itemid ." and clock>$from_time and clock<$to_time group by round(900*((clock+$z)%($p))/($p))"; - $result=DBselect($sql); - while($row=DBfetch($result)) + function drawElement($item,$x1,$y1,$x2,$y2) + { + if($this->items[$item]["drawtype"] == GRAPH_DRAW_TYPE_LINE) { - $i=$row["i"]; - $count[$i]=$row["count"]; - $min[$i]=$row["min"]; - $max[$i]=$row["max"]; - $avg[$i]=$row["avg"]; - $nodata=0; + ImageLine($this->im,$x1,$y1,$x2,$y2,$this->colors[$this->items[$item]["color"]]); } - - if($nodata!=0) + else if($this->items[$item]["drawtype"] == GRAPH_DRAW_TYPE_BOLDLINE) { - $this->noDataFound(); - exit; + ImageLine($this->im,$x1,$y1,$x2,$y2,$this->colors[$this->items[$item]["color"]]); + ImageLine($this->im,$x1,$y1+1,$x2,$y2+1,$this->colors[$this->items[$item]["color"]]); } - -// echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>"; - $minX=0; - $maxX=900; - $maxY=max($avg); - $minY=min($avg); - - if(isset($minY)&&($maxY)&&($minX!=$maxX)&&($minY!=$maxY)) - { - for($i=0;$i<900;$i++) - { - if($count[$i]>0) + else if($this->items[$item]["drawtype"] == GRAPH_DRAW_TYPE_FILL) { - $x1=$this->sizeX*($i-$minX)/($maxX-$minX); - $y1=$this->sizeY*($avg[$i]-$minY)/($maxY-$minY); - $x1=$this->sizeX-$x1; - $y1=$this->sizeY-$y1; + $a[0]=$x1; + $a[1]=$y1; + $a[2]=$x1; + $a[3]=$this->shiftY+$this->sizeY; + $a[4]=$x2; + $a[5]=$this->shiftY+$this->sizeY; + $a[6]=$x2; + $a[7]=$y2; - for($j=$i-1;$j>=0;$j--) - { - if($count[$j]>0) - { - $x2=$this->sizeX*($j-$minX)/($maxX-$minX); - $y2=$this->sizeY*($avg[$j]-$minY)/($maxY-$minY); - $x2=$this->sizeX-$x2; - $y2=$this->sizeY-$y2; - ImageLine($this->im,$x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY,$this->colors["Dark Green"]); - break; - } - } + ImageFilledPolygon($this->im,$a,4,$this->colors[$this->items[$item]["color"]]); } -// echo $this->sizeX*($i-$minX)/($maxX-$minX),":",$y1,"<br>"; } - } - $startTime=$minX; - if (($maxX-$minX) < 300) - $precTime=10; - elseif (($maxX-$minX) < 3600 ) - $precTime=60; - else - $precTime=300; - - if (($maxX-$minX) < 1200 ) - $dateForm="H:i:s"; - else - $dateForm="H:i:s"; + function SelectData() + { + $now = time(NULL); + $this->to_time=$now-3600*$this->from; + $this->from_time=$this->to_time-$this->period-3600*$this->from; - $correctTime=$startTime % $precTime; - $stepTime=ceil(ceil(($maxX-$minX)/20)/$precTime)*(1.0*$precTime); + $p=$this->to_time-$this->from_time; + $z=$p-$this->from_time%$p; -/* for($i=1;$i<$my_steps;$i++) + $str=" "; + for($i=0;$i<$this->num;$i++) { - ImageDashedLine($this->im,$this->shiftX,$i/$my_steps*$this->sizeY+$this->shiftY,$this->sizeX+$this->shiftX,$i/$my_steps*$this->sizeY+$this->shiftY,$this->colors["Gray"]); + $str=$str.$this->items[$i]["itemid"].","; } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) - { - ImageDashedLine($this->im,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->shiftY,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->sizeY+$this->shiftY,$this->colors["Gray"]); - }*/ + $str=substr($str,0,strlen($str)-1); - - if($nodata == 0) - { -/* for($i=0;$i<=$my_steps;$i++) - { - ImageString($this->im, 1, $this->sizeX+5+$this->shiftX, $i/$my_steps*$this->sizeY+$this->shiftY-4, convert_units($maxY-$i/$my_steps*($maxY-$minY),$this->item["units"],$this->item["multiplier"]) , $this->colors["Dark Red"]); - }*/ - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) - { -// ImageStringUp($this->im,0,$this->shiftX+($this->sizeX*$j)/($maxX-$minX),$this->shiftY+$this->sizeY+53,date($dateForm,$startTime+$j),$this->colors["Black"]); - } - -// ImageString($this->im, 1,10, $this->sizeY+$this->shiftY+5, date("dS of F Y H:i:s",$minX) , $this->colors["Dark Red"]); -// ImageString($this->im, 1,$this->sizeX+$this->shiftX-148,$this->sizeY+$this->shiftY+5, date("dS of F Y H:i:s",$maxX) , $this->colors["Dark Red"]); - } - else + $sql="select itemid,round(900*((clock+$z)%($p))/($p)) as i,count(*) as count,avg(value) as avg,min(value) as min,max(value) as max from history where itemid in ($str) and clock>=".$this->from_time." and clock<=".$this->to_time." group by itemid,round(900*((clock+$z)%($p))/($p))"; +// echo $sql; + + $result=DBselect($sql); + while($row=DBfetch($result)) { - ImageString($this->im, 2,$this->sizeX/2-50, $this->sizeY+$this->shiftY+3, "NO DATA FOUND FOR THIS PERIOD" , $this->colors["Dark Red"]); + $i=$row["i"]; + $this->count[$this->itemids[$row["itemid"]]][$i]=$row["count"]; + $this->min[$this->itemids[$row["itemid"]]][$i]=$row["min"]; + $this->max[$this->itemids[$row["itemid"]]][$i]=$row["max"]; + $this->avg[$this->itemids[$row["itemid"]]][$i]=$row["avg"]; + $this->nodata=0; } - - $this->drawLogo(); - - - ImagePng($this->im); - ImageDestroy($this->im); } - function Draw3() + function Draw() { - $start_time=time(NULL); + $start_time=getmicrotime(); $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40); - $nodata=1; -// Header( "Content-type: text/html"); - Header( "Content-type: image/png"); + Header( "Content-type: text/html"); +// Header( "Content-type: image/png"); Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); check_authorisation(); @@ -441,168 +313,83 @@ $this->initColors(); $this->drawRectangle(); $this->drawHeader(); - if(!check_right("Item","R",$this->itemid)) - { - ImagePng($this->im); - ImageDestroy($this->im); - exit; - } + $this->checkPermissions(); - $now = time(NULL); -// $to_time=$now-$now%$this->period; - $to_time=$now; -// $from_time=$to_time-17*$this->period; - $from_time=$to_time-$this->period; - - $count=array(); - for($i=0;$i<900;$i++) $count[$i]=0; - $min=array(); - $max=array(); - $avg=array(); - $p=$to_time-$from_time; -// $z=$from_time%$p; - $z=$p-$from_time%$p; - $sql="select round(900*((clock+$z)%($p))/($p)) as i,count(*) as count,avg(value) as avg,min(value) as min,max(value) as max from history where itemid=".$this->item["itemid"]." and clock>=$from_time and clock<=$to_time group by round(900*((clock+$z)%($p))/($p))"; -// $sql="select round(900*((clock+3*3600)%(3600))/(3600)) as i,count(*) as count,avg(value) as avg,min(value) as min,max(value) as max from history where itemid=".$this->item["itemid"]." and clock>=$from_time and clock<=$to_time group by round(900*((clock+3*3600)%($p))/($p))"; -// echo $sql,"<br>"; -// echo $to_time-$from_time,"<br>"; + $this->SelectData(); - $result=DBselect($sql); - while($row=DBfetch($result)) - { - $i=$row["i"]; - $count[$i]=$row["count"]; - $min[$i]=$row["min"]; - $max[$i]=$row["max"]; - $avg[$i]=$row["avg"]; - $nodata=0; - } + $this->drawGrid(); - - for($i=0;$i<=$this->sizeY;$i+=$this->sizeY/6) - { - ImageDashedLine($this->im,$this->shiftX,$i+$this->shiftY,$this->sizeX+$this->shiftX,$i+$this->shiftY,$this->colors["Gray"]); - } - - for($i=0;$i<=$this->sizeX;$i+=$this->sizeX/24) + $maxX=900; + $minX=0; + unset($maxY); + for($i=0;$i<$this->num;$i++) { - ImageDashedLine($this->im,$i+$this->shiftX,$this->shiftY,$i+$this->shiftX,$this->sizeY+$this->shiftY,$this->colors["Gray"]); - if($nodata == 0) + if(!isset($maxY)) + { + if(count($this->max[$i])>0) + { + $maxY=max($this->max[$i]); + } + } + else { - ImageStringUp($this->im, 1,$i+$this->shiftX-3, $this->sizeY+$this->shiftY+29, date($this->date_format,$from_time+$i*$this->period/$this->sizeX) , $this->colors["Black"]); -// echo $from_time," ",$to_time," ",$from_time+$i*$this->period/$this->sizeX,"<br>"; + $maxY=@iif($maxY<max($this->max[$i]),max($this->max[$i]),$maxY); } } - - $maxX=900; - $minX=0; - $maxY=@iif(count($max)>0,max($max),0); - $minY=@iif(count($min)>0,min($min),0); $minY=0; -// $maxY=30000; - # echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>"; - if(isset($minY)&&($maxY)&&($minX!=$maxX)&&($minY!=$maxY)) + if(isset($minY)&&isset($maxY)&&($minX!=$maxX)&&($minY!=$maxY)) { - for($i=0;$i<900;$i++) + for($item=0;$item<$this->num;$item++) { - if($count[$i]>0) + for($i=0;$i<900;$i++) { - $x1=$this->sizeX*($i-$minX)/($maxX-$minX); - $y1=$this->sizeY*($max[$i]-$minY)/($maxY-$minY); - $y1=$this->sizeY-$y1; - for($j=$i-1;$j>=0;$j--) - { - if($count[$j]>0) - { - $x2=$this->sizeX*($j-$minX)/($maxX-$minX); - $y2=$this->sizeY*($max[$j]-$minY)/($maxY-$minY); - $y2=$this->sizeY-$y2; - ImageLine($this->im,$x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY,$this->colors["Dark Red"]); - break; - } - } - - $x1=$this->sizeX*($i-$minX)/($maxX-$minX); - $y1=$this->sizeY*($avg[$i]-$minY)/($maxY-$minY); - $y1=$this->sizeY-$y1; - for($j=$i-1;$j>=0;$j--) + if($this->count[$item][$i]>0) { - if($count[$j]>0) +// for($j=$i-1;($j>=0)&&($j>$i-10);$j--) + for($j=$i-1;$j>=0;$j--) { - $x2=$this->sizeX*($j-$minX)/($maxX-$minX); - $y2=$this->sizeY*($avg[$j]-$minY)/($maxY-$minY); - $y2=$this->sizeY-$y2; - ImageLine($this->im,$x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY,$this->colors["Dark Yellow"]); - break; - } - } - - $x1=$this->sizeX*($i-$minX)/($maxX-$minX); - $y1=$this->sizeY*($min[$i]-$minY)/($maxY-$minY); - $y1=$this->sizeY-$y1; - for($j=$i-1;$j>=0;$j--) - { - if($count[$j]>0) - { - $x2=$this->sizeX*($j-$minX)/($maxX-$minX); - $y2=$this->sizeY*($min[$j]-$minY)/($maxY-$minY); - $y2=$this->sizeY-$y2; - ImageLine($this->im,$x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY,$this->colors["Dark Green"]); - break; + if($this->count[$item][$j]>0) + { + $x1=$this->sizeX*($i-$minX)/($maxX-$minX); + $y1=$this->sizeY*($this->avg[$item][$i]-$minY)/($maxY-$minY); + $y1=$this->sizeY-$y1; + + $x2=$this->sizeX*($j-$minX)/($maxX-$minX); + $y2=$this->sizeY*($this->avg[$item][$j]-$minY)/($maxY-$minY); + $y2=$this->sizeY-$y2; + + $this->drawElement($item, $x1+$this->shiftX,$y1+$this->shiftY,$x2+$this->shiftX,$y2+$this->shiftY); + break; + } } } } } } - if($nodata == 0) + if($this->nodata == 0) { - for($i=0;$i<=$this->sizeY;$i+=$this->sizeY/6) + for($i=0;$i<=6;$i++) { - ImageString($this->im, 1, $this->sizeX+5+$this->shiftX, $this->sizeY-$i-4+$this->shiftY, convert_units($i*($maxY-$minY)/$this->sizeY+$minY,$this->item["units"],$this->item["multiplier"]) , $this->colors["Dark Red"]); + ImageString($this->im, 1, $this->sizeX+5+$this->shiftX, $this->sizeY-$this->sizeY*$i/6-4+$this->shiftY, convert_units($this->sizeY*$i/6*($maxY-$minY)/$this->sizeY+$minY,$this->items[0]["units"],$this->items[0]["multiplier"]) , $this->colors["Dark Red"]); } } else { ImageString($this->im, 2,$this->sizeX/2 -50,$this->sizeY+$this->shiftY+3, "NO DATA FOR THIS PERIOD" , $this->colors["Dark Red"]); } - -{ -// ImageFilledRectangle($this->im,$this->shiftX,$this->sizeY+$this->shiftY+25*(0)+20,$this->shiftX+5,$this->sizeY+$this->shiftY+9+25*(0)+20,$this->colors["Dark Green"]); -// ImageRectangle($this->im,$this->shiftX,$this->sizeY+$this->shiftY+25*(0)+20,$this->shiftX+5,$this->sizeY+$this->shiftY+9+25*(0)+20,$this->colors["Black"]); -/* ImageRectangle($im,$shiftX,$sizeY+$shiftYup+19+15*$item+45,$shiftX+5,$sizeY+$shiftYup+15+9+15*$item+45,$black); - $max_host_len=0; - $max_desc_len=0; - for($i=0;$i<DBnum_rows($result2);$i++) - { - $z=get_item_by_itemid($iids[$i]); - $h=get_host_by_hostid($z["hostid"]); - if(strlen($h["host"])>$max_host_len) $max_host_len=strlen($h["host"]); - if(strlen($z["description"])>$max_desc_len) $max_desc_len=strlen($z["description"]); - } - $i=get_item_by_itemid($iids[$item]); - $str=sprintf("%s: %s [last:%s min:%s avg:%s max:%s]", str_pad($host[$item],$max_host_len," "), str_pad($desc[$item],$max_desc_len," "), convert_units($y[$item][$len[$item]-1],$i["units"],$i["multiplier"]), convert_units($itemMin,$i["units"],$i["multiplier"]), convert_units($itemAvg,$i["units"],$i["multiplier"]), convert_units($itemMax,$i["units"],$i["multiplier"])); - if($width>600) - { - ImageString($im, 2,$shiftX+9,$sizeY+$shiftYup+15*$item+15+45,$str, $black); - } - else - { - ImageString($im, 0,$shiftX+9,$sizeY+$shiftYup+15*$item+17+45,$str, $black); - } - }*/ -} - - ImageString($this->im, 1,$this->shiftX, $this->sizeY+$this->shiftY+35, "MIN" , $this->colors["Dark Green"]); - ImageString($this->im, 1,$this->shiftX+20, $this->sizeY+$this->shiftY+35, "AVG" , $this->colors["Dark Yellow"]); - ImageString($this->im, 1,$this->shiftX+40, $this->sizeY+$this->shiftY+35, "MAX" , $this->colors["Dark Red"]); - ImageStringUp($this->im,0,imagesx($this->im)-10,imagesy($this->im)-50, "http://zabbix.sourceforge.net", $this->colors["Gray"]); + + + + + $this->drawLegend(); - $end_time=time(NULL); - ImageString($this->im, 0,imagesx($this->im)-100,imagesy($this->im)-12,"Generated in ".($end_time-$start_time)." sec", $this->colors["Gray"]); - + $end_time=getmicrotime(); + $str=sprintf("%0.2f",($end_time-$start_time)); + ImageString($this->im, 0,imagesx($this->im)-120,imagesy($this->im)-12,"Generated in $str sec", $this->colors["Gray"]); + ImagePng($this->im); ImageDestroy($this->im); } |
