1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
<?
include "include/config.inc";
# PARAMETERS:
# itemid
# type
if(!isset($type))
{
$type="hourl";
}
if($type == "15min")
{
$period=900;
$label_format="H:i";
}
else if($type == "30min")
{
$period=1800;
$label_format="H:i";
}
else if($type == "4hours")
{
$period=4*3600;
$label_format="H:i";
}
else if($type == "12hours")
{
$period=12*3600;
$label_format="H:i";
}
else
{
$period=3600;
$label_format="H:i";
}
$sizeX=900;
$sizeY=200;
$shiftX=10;
$shiftY=15;
$nodata=1;
// Header( "Content-type: text/html");
Header( "Content-type: image/png");
Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");
$im = imagecreate($sizeX+$shiftX+61,$sizeY+2*$shiftY+10);
$red=ImageColorAllocate($im,255,0,0);
$green=ImageColorAllocate($im,0,255,0);
$darkgreen=ImageColorAllocate($im,0,150,0);
$blue=ImageColorAllocate($im,0,0,255);
$yellow=ImageColorAllocate($im,255,255,0);
$cyan=ImageColorAllocate($im,0,255,255);
$black=ImageColorAllocate($im,0,0,0);
$gray=ImageColorAllocate($im,150,150,150);
$x=imagesx($im);
$y=imagesy($im);
ImageFilledRectangle($im,0,0,$sizeX+$shiftX+61,$sizeY+2*$shiftY+10,$black);
$now = time(NULL);
$to_time=$now-$now%$period;
$from_time=$to_time-17*$period;
for($i=0;$i<=$sizeY;$i+=50)
{
ImageDashedLine($im,$shiftX,$i+$shiftY,$sizeX+$shiftX,$i+$shiftY,$darkgreen);
}
for($i=0;$i<=$sizeX;$i+=50)
{
ImageDashedLine($im,$i+$shiftX,$shiftY,$i+$shiftX,$sizeY+$shiftY,$darkgreen);
ImageString($im, 1,$i+$shiftX-11, $sizeY+$shiftY+5, date($label_format,$from_time+$period*($i/50)) , $red);
}
$count=array();
$min=array();
$max=array();
$avg=array();
for($i=0;$i<900;$i++)
{
$result=DBselect("select count(value),min(value),max(value),avg(value) from history where itemid=$itemid and clock>$from_time+$i*($to_time-$from_time)/(900-50) and clock<$from_time+($i+1)*($to_time-$from_time)/(900-50)");
$count[$i]=DBget_field($result,0,0);
$min[$i]=DBget_field($result,0,1);
$max[$i]=DBget_field($result,0,2);
$avg[$i]=DBget_field($result,0,3);
}
$maxY=-1000000000;
$minY=1000000000;
for($i=0;$i<900;$i++)
{
$nodata=0;
if($max[$i]>$maxY) { $maxY=$max[$i]; }
if(($min[$i]<$minY)&&($count[$i]>0)) { $minY=$min[$i]; }
}
$maxX=900;
$minX=0;
# echo "MIN/MAX:",$minX," - ",$maxX," - ",$minY," - ",$maxY,"<Br>";
if(($minX!=$maxX)&&($minY!=$maxY))
{
for($i=0;$i<900;$i++)
{
if($count[$i]>0)
{
$x1=$sizeX*($i-$minX)/($maxX-$minX);
$y1=$sizeY*($max[$i]-$minY)/($maxY-$minY);
$x2=$x1;
$y2=0;
$y1=$sizeY-$y1;
$y2=$sizeY-$y2;
ImageLine($im,$x1+$shiftX,$y1+$shiftY,$x2+$shiftX,$y2+$shiftY,$red);
$x1=$sizeX*($i-$minX)/($maxX-$minX);
$y1=$sizeY*($avg[$i]-$minY)/($maxY-$minY);
$x2=$x1;
$y2=0;
$y1=$sizeY-$y1;
$y2=$sizeY-$y2;
ImageLine($im,$x1+$shiftX,$y1+$shiftY,$x2+$shiftX,$y2+$shiftY,$yellow);
$x1=$sizeX*($i-$minX)/($maxX-$minX);
$y1=$sizeY*($min[$i]-$minY)/($maxY-$minY);
$x2=$x1;
$y2=0;
$y1=$sizeY-$y1;
$y2=$sizeY-$y2;
ImageLine($im,$x1+$shiftX,$y1+$shiftY,$x2+$shiftX,$y2+$shiftY,$green);
}
# ImageStringUp($im, 1, $x1+10, $sizeY+$shiftY+15, $i , $red);
}
}
else
{
ImageLine($im,$shiftX,$shiftY+$sizeY/2,$sizeX+$shiftX,$shiftY+$sizeY/2,$green);
}
if($nodata == 0)
{
for($i=0;$i<=$sizeY;$i+=50)
{
ImageString($im, 1, $sizeX+5+$shiftX, $sizeY-$i-4+$shiftY, $i*($maxY-$minY)/$sizeY+$minY , $red);
}
// date("dS of F Y h:i:s A",DBget_field($result,0,0));
// ImageString($im, 1,10, $sizeY+$shiftY+5, date("dS of F Y h:i:s A",$minX) , $red);
// ImageString($im, 1,$sizeX+$shiftX-168,$sizeY+$shiftY+5, date("dS of F Y h:i:s A",$maxX) , $red);
}
else
{
ImageString($im, 2,$sizeX/2 -50, $sizeY+$shiftY+3, "NO DATA FOR THIS PERIOD" , $red);
}
ImageString($im, 1,$shiftX, $sizeY+$shiftY+15, "MIN" , $green);
ImageString($im, 1,$shiftX+20, $sizeY+$shiftY+15, "AVG" , $yellow);
ImageString($im, 1,$shiftX+40, $sizeY+$shiftY+15, "MAX" , $red);
ImageStringUp($im,0,2*$shiftX+$sizeX+40,$sizeY+2*$shiftY, "http://zabbix.sourceforge.net", $gray);
ImagePng($im);
ImageDestroy($im);
?>
|