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/chart2.php | |
parent | 1a7b74a3fc4ea2b0264eb620e44654eeb3e6c081 (diff) | |
download | zabbix-6822f3a55614b2c2ed10479e63f6c39526b08708.tar.gz zabbix-6822f3a55614b2c2ed10479e63f6c39526b08708.tar.xz zabbix-6822f3a55614b2c2ed10479e63f6c39526b08708.zip |
Minor changes (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@882 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/chart2.php')
-rw-r--r-- | frontends/php/chart2.php | 391 |
1 files changed, 37 insertions, 354 deletions
diff --git a/frontends/php/chart2.php b/frontends/php/chart2.php index 97c59fbc..bf8a79ad 100644 --- a/frontends/php/chart2.php +++ b/frontends/php/chart2.php @@ -1,26 +1,39 @@ <?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 include "include/config.inc.php"; + include "include/classes.inc.php"; -# PARAMETERS: - -# graphid - -# period -# from -# force_miny -# force_maxy -# refresh - - $start_time=time(NULL); - - if(!isset($HTTP_GET_VARS["period"])) + $graph=new Graph(); + if(isset($HTTP_GET_VARS["period"])) { - $HTTP_GET_VARS["period"]=0; + $graph->setPeriod($HTTP_GET_VARS["period"]); } - - if(!isset($HTTP_GET_VARS["from"])) + if(isset($HTTP_GET_VARS["from"])) + { + $graph->setFrom($HTTP_GET_VARS["from"]); + } + if(isset($HTTP_GET_VARS["border"])) { - $HTTP_GET_VARS["from"]=0; + $graph->setBorder(0); } $result=DBselect("select name,width,height from graphs where graphid=".$HTTP_GET_VARS["graphid"]); @@ -43,346 +56,16 @@ $height=DBget_field($result,0,2); } - $sizeX=$width; - $sizeY=$height; - - $nodata=1; - -// Header( "Content-type: text/html"); - Header( "Content-type: image/png"); - Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT"); - - check_authorisation(); - - $result2=DBselect("select gi.itemid,i.description,gi.color,h.host,gi.drawtype from graphs_items gi,items i,hosts h where gi.itemid=i.itemid and gi.graphid=".$HTTP_GET_VARS["graphid"]." and i.hostid=h.hostid order by gi.gitemid"); - - $shiftX=10; - $shiftYup=17; - $shiftYdown=7+15*DBnum_rows($result2); - - $im = imagecreate($sizeX+$shiftX+61,$sizeY+$shiftYup+$shiftYdown+10+50); - - $red=ImageColorAllocate($im,255,0,0); - $darkred=ImageColorAllocate($im,150,0,0); - $green=ImageColorAllocate($im,0,255,0); - $darkgreen=ImageColorAllocate($im,0,150,0); - $blue=ImageColorAllocate($im,0,0,255); - $darkblue=ImageColorAllocate($im,0,0,150); - $yellow=ImageColorAllocate($im,255,255,0); - $darkyellow=ImageColorAllocate($im,150,150,0); - $cyan=ImageColorAllocate($im,0,255,255); - $black=ImageColorAllocate($im,0,0,0); - $white=ImageColorAllocate($im,255,255,255); - $gray=ImageColorAllocate($im,150,150,150); - - $colors=array(); - - $colors["Black"]=$black; - $colors["Green"]=$green; - $colors["Dark Green"]=$darkgreen; - $colors["Yellow"]=$yellow; - $colors["Dark Yellow"]=$darkyellow; - $colors["Blue"]=$blue; - $colors["Dark Blue"]=$darkblue; - $colors["White"]=$white; - $colors["Cyan"]=$cyan; - $colors["Red"]=$red; - $colors["Dark Red"]=$darkred; - - $x=imagesx($im); - $y=imagesy($im); - - ImageFilledRectangle($im,0,0,$sizeX+$shiftX+61,$sizeY+$shiftYup+$shiftYdown+10+50,$white); - if(!isset($HTTP_GET_VARS["noborder"])) - { - ImageRectangle($im,0,0,$x-1,$y-1,$black); - } -// ImageRectangle($im,$shiftX+1,$shiftYup,$shiftX+$sizeX,$shiftYup+$sizeY, $black ); - - ImageDashedLine($im,$shiftX+1,$shiftYup,$shiftX+1,$sizeY+$shiftYup,$black); - ImageDashedLine($im,$shiftX+1,$shiftYup,$shiftX+$sizeX,$shiftYup,$black); - ImageDashedLine($im,$shiftX+$sizeX,$shiftYup,$shiftX+$sizeX,$sizeY+$shiftYup,$black); - ImageDashedLine($im,$shiftX+1,$shiftYup+$sizeY,$shiftX+$sizeX,$sizeY+$shiftYup,$black); - - if(!check_right("Graph","R",$HTTP_GET_VARS["graphid"])) - { -// show_table_header("<font color=\"AA0000\">No permissions !</font>"); -// show_footer(); - ImagePng($im); - ImageDestroy($im); - exit; - } - - $graph=get_graph_by_graphid($HTTP_GET_VARS["graphid"]); - $str=$graph["name"]; - $x=imagesx($im)/2-ImageFontWidth(4)*strlen($str)/2; - ImageString($im, 4,$x,1, $str , $darkred); - - $from_time = time(NULL)-$HTTP_GET_VARS["period"]-3600*$HTTP_GET_VARS["from"]; - $to_time = time(NULL)-3600*$HTTP_GET_VARS["from"]; - - $len=array(); - $x=array(); - $y=array(); - $desc=array(); - $iids=array(); - $color=array(); - $drawtype=array(); - - unset($maxX); - unset($maxY); - unset($minX); - unset($minY); - - for($item=0;$item<DBnum_rows($result2);$item++) - { - $itemid=DBget_field($result2,$item,0); - $iids[$item]=$itemid; - $desc[$item]=DBget_field($result2,$item,1); - $color[$item]=DBget_field($result2,$item,2); - $host[$item]=DBget_field($result2,$item,3); - $drawtype[$item]=DBget_field($result2,$item,4); - - $result=DBselect("select clock,value from history where itemid=$itemid and clock>$from_time and clock<$to_time order by clock"); - $len[$item]=0; - $x[$item]=array(); - $y[$item]=array(); - for($i=0;$i<DBnum_rows($result);$i++) - { - $nodata=0; - $x[$item][$len[$item]]=DBget_field($result,$i,0); - $y[$item][$len[$item]]=DBget_field($result,$i,1);; - // echo $row[0]," - ",$y[$len],"<Br>"; - if((!isset($maxX))||($x[$item][$len[$item]]>$maxX)) { $maxX=$x[$item][$len[$item]]; } - if((!isset($minX))||($x[$item][$len[$item]]<$minX)) { $minX=$x[$item][$len[$item]]; } - if((!isset($maxY))||($y[$item][$len[$item]]>$maxY)) { $maxY=$y[$item][$len[$item]]; } - if((!isset($minY))||($y[$item][$len[$item]]<$minY)) { $minY=$y[$item][$len[$item]]; } - $len[$item]++; - } - } - - if($nodata==1) - { - ImageString($im, 2,$sizeX/2-50, $sizeY+$shiftYup+3, "NO DATA FOUND FOR THIS PERIOD" , $darkred); - ImageStringUp($im,0,imagesx($im)-10,imagesy($im)-50, "http://zabbix.sourceforge.net", $gray); - - ImagePng($im); - ImageDestroy($im); - exit; - } - -// echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>"; - if(isset($HTTP_GET_VARS["force_miny"])) - { - $minY = $HTTP_GET_VARS["force_miny"]; - } - if(isset($HTTP_GET_VARS["force_maxy"])) - { - $maxY = $HTTP_GET_VARS["force_maxy"]; - } - - $my_exp=iif($maxY!=0,floor(log10($maxY)),0); - $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; -/* - $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($im,$shiftX,$i/$my_steps*$sizeY+$shiftYup,$sizeX+$shiftX,$i/$my_steps*$sizeY+$shiftYup,$gray); - } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) - { - ImageDashedLine($im,$shiftX+($sizeX*$j)/($maxX-$minX),$shiftYup,$shiftX+($sizeX*$j)/($maxX-$minX),$sizeY+$shiftYup,$gray); - } - -*/ -// $result2=DBselect("select itemid from graphs_items where graphid=".$HTTP_GET_VARS["graphid"]); - for($item=0;$item<DBnum_rows($result2);$item++) - { - if(isset($minX)&&isset($minY)&&($minX!=$maxX)&&($minY!=$maxY)) - { - $itemMin = $y[$item][0]; - $itemMax = $y[$item][0]; - $itemAvg = $y[$item][0]; - for($i=0;$i<$len[$item]-1;$i++) - { - $x1=$sizeX*($x[$item][$i]-$minX)/($maxX-$minX); - $y1=$sizeY*($y[$item][$i]-$minY)/($maxY-$minY); - $x2=$sizeX*($x[$item][$i+1]-$minX)/($maxX-$minX); - $y2=$sizeY*($y[$item][$i+1]-$minY)/($maxY-$minY); - - $y1=$sizeY-$y1; - $y2=$sizeY-$y2; - - // echo $x1," - ",$x2," - ",$y1," - ",$y2,"<Br>"; - if($drawtype[$item]==1) - { - $a[0]=$x1+$shiftX; - $a[1]=$y1+$shiftYup; - $a[2]=$x1+$shiftX; - $a[3]=$shiftYup+$sizeY; - $a[4]=$x2+$shiftX; - $a[5]=$shiftYup+$sizeY; - $a[6]=$x2+$shiftX; - $a[7]=$y2+$shiftYup; - - ImageFilledPolygon($im,$a,4,$colors[$color[$item]]); - } - else if($drawtype[$item]==2) - { - ImageLine($im,$x1+$shiftX,$y1+$shiftYup,$x2+$shiftX,$y2+$shiftYup,$colors[$color[$item]]); - ImageLine($im,$x1+$shiftX,$y1+$shiftYup+1,$x2+$shiftX,$y2+$shiftYup+1,$colors[$color[$item]]); - } -// default or '0' - else - { - ImageLine($im,$x1+$shiftX,$y1+$shiftYup,$x2+$shiftX,$y2+$shiftYup,$colors[$color[$item]]); - } - - $itemMin=min($y[$item][$i+1], $itemMin); - $itemMax=max($y[$item][$i+1], $itemMax); - $itemAvg+=$y[$item][$i+1]; - } - $itemAvg /= $len[$item]; - } - else - { - if(isset($minX)) - { - ImageLine($im,$shiftX,$shiftYup+$sizeY/2,$sizeX+$shiftX,$shiftYup+$sizeY/2,$colors[$color[$item]]); - } - } - ImageFilledRectangle($im,$shiftX,$sizeY+$shiftYup+19+15*$item+45,$shiftX+5,$sizeY+$shiftYup+15+9+15*$item+45,$colors[$color[$item]]); - ImageRectangle($im,$shiftX,$sizeY+$shiftYup+19+15*$item+45,$shiftX+5,$sizeY+$shiftYup+15+9+15*$item+45,$black); -// ImageString($im, 1, $sizeX+5+$shiftX, $i/$my_steps*$sizeY+$shiftYup-4, convert_units($maxY-$i/$my_steps*($maxY-$minY),$z["units"],$z["multiplier"]) , $darkred); -// $str=sprintf("%s: %s [min:%.2f, avg:%.2f, max:%.2f]", $host[$item], $desc[$item], $itemMin, $itemAvg, $itemMax); - $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); - } - } - - $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"; + $graph->setHeader(DBget_field($result,0,0)); + $result=DBselect("select gi.itemid,i.description,gi.color,h.host,gi.drawtype from graphs_items gi,items i,hosts h where gi.itemid=i.itemid and gi.graphid=".$HTTP_GET_VARS["graphid"]." and i.hostid=h.hostid order by gi.gitemid"); - $correctTime=$startTime % $precTime; - $stepTime=ceil(ceil(($maxX-$minX)/20)/$precTime)*(1.0*$precTime); - - for($i=1;$i<$my_steps;$i++) - { - ImageDashedLine($im,$shiftX,$i/$my_steps*$sizeY+$shiftYup,$sizeX+$shiftX,$i/$my_steps*$sizeY+$shiftYup,$gray); - } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) + for($i=0;$i<DBnum_rows($result);$i++) { - ImageDashedLine($im,$shiftX+($sizeX*$j)/($maxX-$minX),$shiftYup,$shiftX+($sizeX*$j)/($maxX-$minX),$sizeY+$shiftYup,$gray); + $graph->addItem(DBget_field($result,$i,0)); + $graph->setColor(DBget_field($result,$i,0), DBget_field($result,$i,2)); } - - if($nodata == 0) - { - for($i=0;$i<=$my_steps;$i++) - { - if(isset($itemid)) - { - $z=get_item_by_itemid($itemid); - ImageString($im, 1, $sizeX+5+$shiftX, $i/$my_steps*$sizeY+$shiftYup-4, convert_units($maxY-$i/$my_steps*($maxY-$minY),$z["units"],$z["multiplier"]) , $darkred); - } - else - { - ImageString($im, 1, $sizeX+5+$shiftX, $i/$my_steps*$sizeY+$shiftYup-4, $maxY-$i/$my_steps*($maxY-$minY) , $darkred); - } - } - for($j=$stepTime-$correctTime;$j<=($maxX-$minX);$j+=$stepTime) - { - ImageStringUp($im,0,$shiftX+($sizeX*$j)/($maxX-$minX),$shiftYup+$sizeY+53,date($dateForm,$startTime+$j),$black); - } - - ImageString($im, 1,10, $sizeY+$shiftYup+5, date("dS of F Y H:i:s",$minX) , $darkred); - ImageString($im, 1,$sizeX+$shiftX-148,$sizeY+$shiftYup+5, date("dS of F Y H:i:s",$maxX) , $darkred); - } - else - { - ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftYup+3, "NO DATA FOR THIS PERIOD" , $red); - } - - ImageStringUp($im,0,imagesx($im)-10,imagesy($im)-50, "http://zabbix.sourceforge.net", $gray); - - $end_time=time(NULL); - ImageString($im, 0,imagesx($im)-100,imagesy($im)-12,"Generated in ".($end_time-$start_time)." sec", $gray); - - ImagePng($im); - ImageDestroy($im); + $graph->Draw(); ?> + |