forked from poppyred/1.6.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.cpustats.php
executable file
·213 lines (161 loc) · 5.5 KB
/
system.cpustats.php
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
header("Pragma: no-cache");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.groups.inc');
include_once('ressources/class.mysql.inc');
include_once('ressources/class.ini.inc');
include_once('ressources/class.squid.inc');
include_once('ressources/class.system.network.inc');
$user=new usersMenus();
if($user->AsSquidAdministrator==false){
$tpl=new templates();
echo "alert('". $tpl->javascript_parse_text("{ERROR_NO_PRIVS}")."');";
die();exit();
}
if(isset($_GET["tabs"])){tabs();exit;}
if(isset($_GET["popup"])){popup();exit;}
if(isset($_GET["yesterday"])){yesterday();exit;}
if(isset($_GET["graph1"])){graph1();exit;}
if(isset($_GET["graph2"])){graph2();exit;}
js();
function tabs(){
$page=CurrentPageName();
$tpl=new templates();
$array["popup"]='{today}';
$array["yesterday"]='{yesterday}';
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$t=time();
while (list ($num, $ligne) = each ($array) ){
$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"$page?$num=ye&t=$t\" style='font-size:16px'><span>$ligne</span></a></li>\n");
}
echo build_artica_tabs($html, "system_cpu_stats");
}
function js(){
$page=CurrentPageName();
$tpl=new templates();
header("content-type: application/x-javascript");
$useragent_database=$tpl->_ENGINE_parse_body("% {cpu}");
$html="YahooWin5('1090','$page?tabs=yes','$useragent_database');";
echo $html;
}
function popup(){
$page=CurrentPageName();
$t=time();
$html="
<div style='float:right'>". imgtootltip("refresh-24.png","{refresh}","RefreshTab('system_cpu_stats')")."</div>
<div id='graph1-$t' style='width:1000px'></div>
<span id='log-$t'></span>
<script>
function FTrois$t(){
AnimateDiv('graph1-$t');
Loadjs('$page?graph1=yes&container=graph1-$t&t=$t',true);
}
function FDay$t(){
AnimateDiv('graph2-$t');
Loadjs('$page?graph2=yes&container=graph2-$t&t=$t',true);
}
setTimeout(\"FTrois$t()\",600);
</script>
";
echo $html;
}
function yesterday(){
$page=CurrentPageName();
$t=time();
$graph="graph2";
$html="
<div style='float:right'>". imgtootltip("refresh-24.png","{refresh}","RefreshTab('system_cpu_stats')")."</div>
<div id='$graph-$t' style='width:1000px'></div>
<span id='log-$t'></span>
<script>
function FTrois$t(){
AnimateDiv('$graph-$t');
Loadjs('$page?$graph=yes&container=$graph-$t&t=$t',true);
}
setTimeout(\"FTrois$t()\",600);
</script>
";
echo $html;
}
function graph1(){
$tpl=new templates();
$page=CurrentPageName();
$t=time();
$CurTime=date("YmdH");
$CurDay=date("Ymd");
$q=new mysql();
$sock=new sockets();
$hostname=$hostname=$sock->GET_INFO("myhostname");
if($hostname==null){$hostname=$sock->getFrameWork("system.php?hostname-g=yes");$sock->SET_INFO($hostname,"myhostname");}
$title="$hostname: %{cpu} {today}";
$timetext="{hour}";
$sql="SELECT DATE_FORMAT(zDate,'%Y-%m-%d') as tdate,hostname,
HOUR(zDate) as `time`,AVG(cpu) as value FROM `cpustats` GROUP BY `time` ,tdate,hostname
HAVING tdate=DATE_FORMAT(NOW(),'%Y-%m-%d') AND `hostname`='$hostname' ORDER BY `time`";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){$tpl->javascript_senderror($q->mysql_error,$_GET["container"]);}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$xdata[]=$ligne["time"];
$ydata[]=$ligne["value"];
}
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title=$title;
$highcharts->TitleFontSize="14px";
$highcharts->AxisFontsize="12px";
$highcharts->yAxisTtitle=" {cpu} % ";
$highcharts->xAxis_labels=true;
$highcharts->LegendPrefix=$tpl->_ENGINE_parse_body("{cpu} ");
$highcharts->LegendSuffix="%";
$highcharts->xAxisTtitle=$timetext;
$highcharts->datas=array("%"=>$ydata);
echo $highcharts->BuildChart();
}
function graph2(){
$tpl=new templates();
$page=CurrentPageName();
$t=time();
$CurTime=date("YmdH");
$CurDay=date("Ymd");
$q=new mysql();
$sock=new sockets();
$hostname=$hostname=$sock->GET_INFO("myhostname");
if($hostname==null){$hostname=$sock->getFrameWork("system.php?hostname-g=yes");$sock->SET_INFO($hostname,"myhostname");}
$title="$hostname: %{cpu} {yesterday}";
$timetext="{hour}";
$sql="SELECT DATE_FORMAT(zDate,'%Y-%m-%d') as tdate,hostname,
HOUR(zDate) as `time`,AVG(cpu) as value FROM `cpustats` GROUP BY `time` ,tdate,hostname
HAVING tdate=DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 DAY),'%Y-%m-%d') AND `hostname`='$hostname' ORDER BY `time`";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){$tpl->javascript_senderror($q->mysql_error,$_GET["container"]);}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$xdata[]=$ligne["time"];
$ydata[]=$ligne["value"];
}
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title=$title;
$highcharts->TitleFontSize="14px";
$highcharts->AxisFontsize="12px";
$highcharts->yAxisTtitle=" {cpu} % ";
$highcharts->xAxis_labels=true;
$highcharts->LegendPrefix=$tpl->_ENGINE_parse_body("{cpu} ");
$highcharts->LegendSuffix="%";
$highcharts->xAxisTtitle=$timetext;
$highcharts->datas=array("{%}"=>$ydata);
echo $highcharts->BuildChart();
}
function timejs(){
header("content-type: application/x-javascript");
$t=rand(50, 100);
echo "Graph1Newtime='$t';";
}