source: devel/www/statistic/loadgraph.php@ 95

Last change on this file since 95 was 95, checked in by george, 17 years ago
  • Přidáno: Soubory staré statistiky.
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1<?
2include('../db.php');
3DB_Init('localhost','root','','is');
4
5if(!array_key_exists('count',$_GET)) die('Musíte zadat poèet jednotek');
6if(!array_key_exists('size',$_GET)) die('Musíte zadat velikost jednotky');
7if(!array_key_exists('type',$_GET)) $type = ''; else $type = $_GET['type'];
8if($type=='') $type = 'down+up';
9$nasobek = 1/60;
10if($type=='cpu') $nasobek = 100;
11if($type=='online_hosts') $nasobek = 1;
12
13$Pocet = $_GET['count'];
14$Jednotka = $_GET['size'];
15$Sirka = 750;
16$Vyska = 200;
17//$Pocet = 24;
18//$Jednotka = 60;
19
20$Velikost = $Jednotka/($Sirka/$Pocet);
21$Krok = $Sirka/$Pocet;
22//$Pocet = floor($Sirka/$Krok)+1;
23
24header("Content-type: image/png");
25header("Cache-Control: no-cache"); // Dynamický graf neke±ovat
26//$string = $_GET['text'];
27$im = @imagecreate($Sirka, $Vyska+14);
28$background_color = imagecolorallocate($im, 255, 255, 255);
29$black = imagecolorallocate($im, 0,0,0);
30$gray = imagecolorallocate($im, 200,200,200);
31$modra = imagecolorallocate($im, 100,100,255);
32$red = imagecolorallocate($im, 255,180,180);
33
34// Zobraz mìøítko X
35/*
36if($Pocet>)
37{
38 $PocetX = floor($Pocet/60);
39 $KrokX = $Krok*60;
40 if($PocetX>24)
41 {
42 $PocetX = floor($PocetX/24);
43 $KrokX = $KrokX*24;
44 }
45} else {
46 $PocetX = $Pocet;
47 $KrokX = $Krok;
48}
49*/
50$PocetX = $Pocet;
51$KrokX = $Krok;
52for($i=0;$i<=$PocetX;$i++)
53{
54 $x = $i*$KrokX;
55 imageline($im,$x,0,$x,$Vyska,$gray);
56 imagestring($im,2,$x+2,$Vyska,'-'.($PocetX-$i),$black);
57}
58
59if($Jednotka<($Sirka/$Pocet))
60{
61 $Velikost = $Jednotka;
62} else {
63 $Pocet = $Sirka;
64 $Krok = $Sirka/$Pocet;
65}
66
67//echo('Maximum...<br>');
68//flush();
69
70// Zji¹tìní maxima
71DB_Query('SELECT ('.$type.') FROM traffic ORDER BY time DESC LIMIT 0,'.$Pocet*$Velikost);
72while($Row = DB_Row())
73{
74 if($Max < $Row[0]) $Max = $Row[0];
75}
76
77//$Max = 60*85000;
78// WHERE (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(time)) <= (60*'.$Pocet.')');
79//$Row = DB_Row();
80$Max = floor($Max*$nasobek*1.01);
81
82// Zobraz mìøítko Y
83$PocetY = (floor($Max/5120));
84for($i=0;$i<=$PocetY;$i++)
85{
86 $y = $Vyska-1-(5120*$i/$Max/1.01*$Vyska);
87 imageline($im,0,$y,$Sirka-1,$y,$gray);
88 imagestring($im,2,2,$y,$i*5,$black);
89}
90
91// Ramecek
92imagerectangle($im,0,0,$Sirka-1,$Vyska-1,$black);
93
94$Ted = time();
95$x = 1;
96$BodyAVG = array();
97$BodyMAX = array();
98for($I=0;$I<$Pocet;$I++)
99{
100 $EndTime = $Ted-$I*60*$Velikost;
101 $StartTime = $EndTime-60*$Velikost;
102 DB_Query('SELECT AVG('.$type.'),MAX('.$type.') FROM traffic WHERE time>FROM_UNIXTIME('.$StartTime.') AND time<FROM_UNIXTIME('.$EndTime.')');
103 $Row = DB_Row();
104 //print_r($Row);
105 //echo($Row[0].' '.$StartTime.'-'.$EndTime.'('.($EndTime-$StartTime).")\n");
106 $Total = $Vyska-2-$Row[0]*$nasobek/$Max*$Vyska+1;
107 $BodyAVG[] = $Sirka-$x;
108 $BodyAVG[] = $Total;
109 $Total = $Vyska-2-$Row[1]*$nasobek/$Max*$Vyska+1;
110 $BodyMAX[] = $Sirka-$x;
111 $BodyMAX[] = $Total;
112 $x += $Krok;
113}
114// Prùmìrování
115/*
116for($i=1;$i<(count($BodyAVG)-8);$i=$i+2)
117{
118 $Body[$i] = ($Body[$i+2]+$Body[$i+4]+$Body[$i+6]+$Body[$i+8])/4;
119}
120*/
121
122array_unshift($BodyAVG,$Vyska-1);
123array_unshift($BodyAVG,$Sirka-1);
124array_unshift($BodyMAX,$Vyska-1);
125array_unshift($BodyMAX,$Sirka-1);
126$BodyAVG[] = 0;
127$BodyAVG[] = $Vyska-1;
128$BodyMAX[] = 0;
129$BodyMAX[] = $Vyska-1;
130imagefilledpolygon($im,$BodyMAX,count($BodyMAX)/2,$red);
131imagefilledpolygon($im,$BodyAVG,count($BodyAVG)/2,$modra);
132//imagepolygon($im,$BodyAVG,count($BodyAVG)/2,$black);
133imagestring($im, 3, $Sirka-94, 5,"Max. ".$Max.' B/s', $black); // Maximum v grafu
134
135// Zobraz popisky Y
136for($i=0;$i<=$PocetY;$i++)
137{
138 $y = $Vyska-1-(5120*$i/$Max/1.01*$Vyska);
139 imagestring($im,2,2,$y,$i*5,$black);
140}
141
142imagepng($im);
143imagedestroy($im);
144?>
Note: See TracBrowser for help on using the repository browser.