-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathman.php
489 lines (463 loc) · 16.1 KB
/
man.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
MaxPermSize<?php
require_once "class.SSH2Opt.php";
require_once 'classDBOpt.php';
if($_GET["type"]=="cpu"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command="cat /proc/cpuinfo";
try{
echo "基础信息:";
echo "<table class='imagetable'>";
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
$strs = '';
foreach ($var as $va){ //将数组 字符串化,用于做统计
$strs = $strs.$va;
}
echo "<tr><td>物理CPU的个数</td><td>".substr_count($strs,'physical id')." 个</td></tr>";
echo "<tr><td>逻辑CPU的个数</td><td>".substr_count($strs,'processor')." 个</td></tr>";
$va = explode(':',$var[4]);
echo "<tr><td>CPU型号</td><td>".$va[1]."</td></tr>";
$va = explode(':',$var[6]);
echo "<tr><td>CPU的主频</td><td>".$va[1]." MHz</td></tr>";
$va = explode(':',$var[7]);
echo "<tr><td>CPU的缓存</td><td>".$va[1]."</td></tr>";
echo "</table>";
echo "<br/>使用信息:";
echo "<table class='imagetable'>";
$var = $opt->ssh2Exec($ip,$user,$pass,"mpstat");
$value=explode(' ',$var[3]);
echo "<tr><th>统计方式</th><th>".$value[3]."</th></tr>";
echo "<tr><td>总使用率</td><td>".$value[7]."%</td></tr>";
echo "<tr><td>系统使用</td><td>".$value[15]."%</td></tr>";
echo "<tr><td>IO等待</td><td>".$value[19]."%</td></tr>";
echo "<tr><td>软件使用</td><td>".$value[27]."%</td></tr>";
echo "<tr><td>剩余</td><td>".$value[38]."%</td></tr>";
echo "</table>";
}catch(PDOException $e){
echo "查询 $ip 失败";
}
}
else if($_GET["type"]=="memory"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command="free -m";
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
$value=explode(' ',$var[2]);
if(count($value) == 3){
array_push($value, $value[2]);
}
echo "<table class='imagetable'>";
echo "<tr><th>内存使用率</th><td>".round($value[1]/($value[1]+$value[3])*100,2)."%</td>";
echo "</table><br/>";
// echo "<table class='imagetable'>";
// echo "<tr><th></th><th>内存总数</th><th>已使用</th><th>空闲内存</th><th>已经废弃</th><th>Buffer缓存内存数</th><th>Page缓存内存</th></tr>";
// echo "<tr><th>内存</th><td>".$value[2]."M</td><td>".$value[3]."M</td><td>".$value[5]."M</td><td>".$value[7]."M</td><td>".$value[9]."M</td><td>".$value[11]."M</td></tr>";
// $value=explode(' ',$var[2]);
// echo "<tr><th>缓存内存</th><td>".$value[1]."M</td><td>".$value[3]."M</td><td></td><td></td><td></td><td></td></tr>";
// $value=explode(' ',$var[3]);
// echo "<tr><th>".$value[0]."</th><td>".$value[2]."M</td><td>".$value[4]."M</td><td>".$value[5]."M</td><td></td><td></td><td></td></tr>";
// echo "</table>";
echo "<table class='imagetable'>";
echo "<tr><th></th><th>内存总数(M)</th><th>已使用(M)</th><th>空闲内存(M)</th><th>已经废弃(M)</th><th>Buffer缓存内存数(M)</th><th>Page缓存内存(M)</th></tr>";
//我也不知道这个for循环该这么备注了 ,总之就是为了获取期望的table。
for ($i=1;$i<count($var);$i++){
$value=explode(' ',$var[$i]);
echo "<tr>";
if ($i == 2){
$num = 1;
foreach($value as $val){
if($val != '' && $val != '-/+'){
if($num == 2){
echo "<td></td>";
}
echo "<td>".$val."</td>";
$num++;
}
}
}else{
foreach($value as $val){
if($val != '' && $val != '-/+'){
echo "<td>".$val."</td>";
}
}
}
echo "</tr>";
}
echo "</table>";
echo <<<EOF
<pre>说明:
Mem开头的行:
内存总数:比如这台机器4G内存,实际上已经扣除掉了作为显存的部分。
已使用 :这部分既包括操作系统本身使用的部分,也包括应用程序已经使用的部分,还包括缓存的部分。
空闲内存:操作系统还没有使用的内存数。我们通常看到这部分比较小。
已经废弃:已经废弃不用,总是显示0。
Buffer缓存内存:作为缓存的内存数
Page缓存内存:作为缓存的内存数
-/+ buffers/cache开头的行:(重点看这行)
已使用 :应用程序总共使用的内存数。等于Mem.used-Mem.buffers-Mem.cached。
空闲内存:是指应用程序还未使用的内存数。这个数据才是我们需要关注的空闲可用内存数。等于Mem.free+Mem.buffers+Mem.cached。
如果此行中free列的数据太小,那么就需要优化程序或者增加物理内存了。
Swap开头的行:为交换分区,在物理内存不够时,才进行Swap交换
详情请参考:Linux free -m 命令详解
EOF;
}catch(PDOException $e){
echo "查询 $ip 失败";
}
}
else if($_GET["type"]=="disk"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command="df -l -m";
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
echo "<table class='imagetable'>";
echo "<tr><th>文件系统</th><th>总计(M)</th><th>已用(M)</th><th>可用(M)</th><th>已用(%)</th><th>挂载点</th></tr>";
for ($i=1;$i<count($var);$i++){
$value=explode(' ',$var[$i]);
echo "<tr>";
foreach($value as $val){
if($val != ''){
echo "<td>".$val."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}catch(PDOException $e){
echo "查询 $ip 失败";
}
}
else if($_GET["type"]=="service"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command="ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head";
$command1="ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head";
try{
$opt=new SSH2Opt();
echo "占用CPU前10的服务<br/>";
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
echo "<table class='imagetable'>";
echo "<tr><th>用户</th><th>PID</th><th>CPU使用率(%)</th><th>内存使用率(%)</th><th>占用虚拟内存(KB)</th><th>占用物理内存(KB)</th><th>进程状态</th><th>开始运行时间</th><th>占用CPU时间</th><th>启动进程命令</th><th>操作</th></tr>";
for ($i=1;$i<count($var);$i++){
$value=explode(' ',$var[$i]);
echo "<tr>";
$num = 1;
$allComm="";
foreach($value as $val){
if($val != '' && $val != '?' && $num < 10){
echo "<td>".$val."</td>";
$num++;
}else{
if ($num > 9){
$allComm=$allComm.$val.' ';
}
}
}
echo "<td title=$allComm>".substr($allComm,0,40)."</td>";
echo "<td><input type='button' value = 'kill' class='but' onclick='kill();'></td>";
echo "</tr>";
}
echo "</table>";
echo "<br/>占用内存前10的服务<br/>";
$var = $opt->ssh2Exec($ip,$user,$pass,$command1);
echo "<table class='imagetable'>";
echo "<tr><th>用户</th><th>PID</th><th>CPU使用率(%)</th><th>内存使用率(%)</th><th>占用虚拟内存(KB)</th><th>占用物理内存(KB)</th><th>进程状态</th><th>开始运行时间</th><th>占用CPU时间</th><th>启动进程命令</th><th>操作</th></tr>";
for ($i=1;$i<count($var);$i++){
$value=explode(' ',$var[$i]);
echo "<tr>";
$num = 1;
$allComm="";
foreach($value as $val){
if($val != '' && $val != '?' && $num < 10){
echo "<td>".$val."</td>";
$num++;
}else{
if ($num > 9){
$allComm=$allComm.$val.' ';
}
}
}
echo "<td title=$allComm>".substr($allComm,0,40)."</td>";
echo "<td><input type='button' value = 'kill' class='but' onclick='kill();'></td>";
echo "</tr>";
}
echo "</table>";
}catch(PDOException $e){
echo "查询 $ip 失败";
}
}
else if($_GET["type"]=="diy"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
echo "<iframe src='diy.php?ip=$ip&user=$user&pass=$pass' frameborder='0' width='100%' height='450px'></iframe>";
}
else if($_GET["type"]=="rmdir"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$dir=$_GET["deldir"];
if($dir == "/" || $dir == "/bin"|| $dir == "/sbin"){ //系统安全不能删除的目录
echo "您删除的目录过于重要,请三思而行.";
}else if($dir == ""){
echo "表逗我,你要删啥?";
}else if(!strstr($dir, '/')){
echo "不好意思,这个目录我不认识啊!";
}else if(substr($dir, -1) == "*"){
echo "最后的*号不用输入,我会补全的!";
}else{
if (substr($dir, -1) != "/"){
$dir=$dir."/";
}
$command = "rm -rf ".$dir."*";
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
foreach ($var as $va){
echo $va."<br/>";
}
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
}
else if($_GET["type"]=="rmfile"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$delfile=$_GET["delfile"];
$command = "rm -f ".$delfile;
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
echo <<<EOF
<script type=text/javascript src="js/jquery-1.8.3.min.js"></script>
<script>
// alert("文件删除成功!");
window.close();
</script>
EOF;
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
//执行多个linux命令,用;隔开
else if($_GET["type"]=="exec"){
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command=$_GET["execml"];
if(substr($command, -1) == ";"){
$command = substr($command,0,strlen($command)-1);
}
$cmds=explode(';',$command);
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Shell($ip,$user,$pass,$cmds);
echo "<pre>".$var."</pre>";
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
//查询tomcat MaxPermSize
else if($_GET["type"]=="MaxPermSize"){
echo '<meta charset="utf-8">';
$ip=$_GET["ip"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$command="ps aux|grep tomcat";
if(substr($command, -1) == ";"){
$command = substr($command,0,strlen($command)-1);
}
$cmds=explode(';',$command);
$iparray=explode('|',$ip);
foreach ($iparray as $ip){
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Shell($ip,$user,$pass,$cmds);
$returns=explode("\n",$var);
$goodret = array();
foreach($returns as $return){
if(strlen($return) > 500){
$returnarray=explode(" ",$return);
$returnarrayg = array_merge(array_unique($returnarray));
array_push($goodret, $returnarrayg);
}
}
echo "<pre>";
echo "<font color='green' size='6'>".$ip."</font>上当前开启的tomcat服务如下:<br/>";
echo "<table border='1' width='700' >";
if(count($goodret) == 0){
echo"<td><font color='red'>该服务器没有查询到tomcat服务</font></td>";
}
for($i = 0; $i < count($goodret); $i ++){
echo "<tr height='40'>";
echo"<td>".substr(strstr($goodret[$i][12], 'tomcat_'), 0,11)."</td>";
$daxiao = (int)($goodret[$i][6])/1024;
echo"<td>".$daxiao." M </td>";
if(strstr($goodret[$i][15], 'Xms')){
echo"<td>".$goodret[$i][15]."</td>";
}else{
echo"<td><font color='red'>没读到 Xms</font></td>";
}
if(strstr($goodret[$i][16], 'Xmx')){
echo"<td>".$goodret[$i][16]."</td>";
}else{
echo"<td><font color='red'>没读到 Xmx</font></td>";
}
if(strstr($goodret[$i][18], 'XX:PermSize')){
echo"<td>".$goodret[$i][18]."</td>";
}else{
echo"<td><font color='red'>没读到 XX:PermSize</font></td>";
}
if(strstr($goodret[$i][19], 'XX:MaxPermSize')){
echo"<td>".$goodret[$i][19]."</td>";
}else{
echo"<td><font color='red'>没读到 XX:MaxPermSize</font></td>";
}
echo "</tr>";
}
echo "</table>";
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
}
//执行单个linux 命令 不做处理
else if($_GET["type"]=="bigfile"){
$ip=$_GET["ip"];
$user=$_GET["user"];
if($user == 'root'){
$pass=$_GET["pass"];
$size=$_GET["size"];
if(floor($size) == $size){
$dw=$_GET["dw"];
$command = 'find / -name "*log*" -size +'.$size.$dw.' -type f -exec ls -lh {} \;|awk \'{ print $9 " --- " $5 }\'';
echo "查询结果为:<br/><br/>";
try{
$opt=new SSH2Opt();
$var = $opt->ssh2Exec($ip,$user,$pass,$command);
foreach ($var as $va){
echo $va."<a href='man.php?type=rmfile&ip=".$ip."&user=".$user."&pass=".$pass."&delfile=".$va."' target = '_black' >删除</a><span style='display:none'>已删除</span><br/><br/>";
}
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}else{
echo "错误:文件大小只能是整数";
}
}else{
echo "错误:您使用的帐号权限不足。";
}
echo <<<EOF
<script type=text/javascript src="js/jquery-1.8.3.min.js"></script>
<script>
$("a").click(function(e){
$(this).fadeOut(5000);
$(this).next("span").fadeIn(5000);
});
</script>
EOF;
}
////////////////////////////////////////////////////////下边是mysql主从同步请求接收
else if($_GET["type"]=="mands"){
$ip="192.168.".$_GET["group"].".16";
$port=$_GET["port"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$sql="show slave status;";
try{
$opt=new classDBOpt();
$vars = $opt->execSql($ip,$port,$user,$pass,$sql);
if(count($vars) == 0){
echo 0;
}else{
echo "<table class='imagetable'>";
echo "<tr><th width='30%'>项目</th><th width='50%'>值</th><th width='20%'>说明/操作</th>";
foreach ($vars as $var){
echo"<tr><th>主从当前状态</th><td>".$var['Slave_IO_State']."</td></tr>";
echo"<tr><th>主机IP地址</th><td>".$var['Master_Host']."</td></tr>";
echo"<tr><th>主机端口</th><td>".$var['Master_Port']."</td></tr>";
if($var['Seconds_Behind_Master'] == 0){
echo"<tr><th>主从同步延时秒数</th><td style='font-size:18px;color:green'>".$var['Seconds_Behind_Master']."</td></tr>";
}else{
echo"<tr><th>主从同步延时秒数</th><td style='font-size:18px;color:red;'>".$var['Seconds_Behind_Master']."(延迟)</td></tr>";
}
if($var['Slave_IO_Running'] == 'Yes'){
echo"<tr><th>Slave_IO_Running</th><td style='font-size:18px;color:green'>".$var['Slave_IO_Running']."</td></tr>";
}else{
echo"<tr><th>Slave_IO_Running</th><td style='font-size:18px;color:red;'>".$var['Slave_IO_Running']."<td>IO挂掉了<br/>请联系管理员处理</td></td></tr>";
echo"<tr><th>最后一次IO错误</th><td >".$var['Last_IO_Error']."</td></tr>";
}
if($var['Slave_SQL_Running'] == 'Yes'){
echo"<tr><th>Slave_SQL_Running</th><td style='font-size:18px;color:green'>".$var['Slave_SQL_Running']."</td></tr>";
}else{
echo"<tr><th>Slave_SQL_Running</th><td style='font-size:18px;color:red;'>".$var['Slave_SQL_Running']."<td><input id='fix' class='but' type='button' onclick='fixSlaveSqlStatus()' value='修复'></td></td></tr>";
echo"<tr><th>最后一次SQL错误</th><td>".$var['Last_SQL_Error']."</td></tr>";
}
}
}
echo "</table>";
echo "<pre>说明:
Slave_IO_Running 和 Slave_SQL_Running 均为 Yes 的时候说明主从同步服务正常运行。
主从同步延时秒数 为0时,说明同步及时
当Slave_SQL_Running 状态为 No的时候,说明/操作 列会 出现“修复”按钮,点击进行修复。
开启自动刷新后,每隔5s刷新一次,如想停止请刷新页面。</pre>";
echo "<input id='allSlaveStatus' class='but' style='background-color:#cccccc;' type='button' onclick='allSlaveStatus()' value='查看全部主从同步信息'>";
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
else if($_GET["type"]=="fix"){
$ip="192.168.".$_GET["group"].".16";
$port=$_GET["port"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$sql1="SLAVE STOP;";
$sql2="SET GLOBAL sql_slave_skip_counter = 1;";
$sql3=" SLAVE START;";
try{
$opt=new classDBOpt();
$vars1 = $opt->execSql($ip,$port,$user,$pass,$sql);
$vars2 = $opt->execSql($ip,$port,$user,$pass,$sql);
$vars3 = $opt->execSql($ip,$port,$user,$pass,$sql);
echo $vars1,$vars2,$vars3;
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
else if($_GET["type"]=="allmands"){
$ip="192.168.".$_GET["group"].".16";
$port=$_GET["port"];
$user=$_GET["user"];
$pass=$_GET["pass"];
$sql="show slave status;";
try{
$opt=new classDBOpt();
$vars = $opt->execSql($ip,$port,$user,$pass,$sql);
echo "<table class='imagetable'>";
echo "<tr><th>项目</th><th>值</th>";
$flag=0;
foreach ($vars[0] as $key=>$a){
if($flag%2 == 1){
$flag++;
continue;
}
echo"<tr><th>".$key."</th><td>".$a."</td></tr>";
$flag++;
}
echo "</table>";
// print_r($vars[0]);
}catch(PDOException $e){
echo "在$ip上 执行删除 失败";
}
}
?>