You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
simple-yewu/frontend/web/jk3.php

97 lines
2.6 KiB

<?php
echo "<br>";echo "<br>";echo "<br>";
if($fp = @fopen('/proc/loadavg', 'r')) {
list($loadaverage) = explode(' ', fread($fp, 6));
echo '系统服务器47.98.20.102负载压力 loadaverage:';
echo $loadaverage;
echo "<br>";
fclose($fp);
if($loadaverage > 2) {
header("HTTP/1.0 503 Service Unavailable");
echo 'server die ';
exit();
}
}
/**
* 记录服务器负载、内存使用、cpu状态,交换分区
* 每10秒检测一次?
*/
//while(1){
exec('top -b -n 1 -d 3',$out);
$Cpu = explode(' ', $out[2]);
$Mem = explode(' ', $out[3]);
$Swap = explode(' ', $out[4]);
//var_dump($Cpu,$Mem,$Swap);
$cpu = str_replace(array('%us,',' '),'',$Cpu[1]);
$mem = str_replace(array('k used,',' '),'',$Mem[2]);
$swap = str_replace(array('k cached',' '),'',$Swap[5]);
date_default_timezone_set('Asia/Shanghai');
echo date('时间y-m-d h:i:s').'<br>CPU:'.$cpu.'<br>内存MEM:'.intval($mem/1024).'<br>交换分区SWAP:'.intval($swap/1024).chr(10);
echo "<br>";
echo "<br>";
echo "Apache服务器httpd用户进程数:";
$cpu2=passthru('ps -efw|grep httpd|wc -l');
echo $cpu2;
echo "<br>";
function check($host, $find)
{$str='';
$fp = fsockopen($host, 80, $errno, $errstr, 10);
if (!$fp)
{
echo "$errstr ($errno)\n";
} else
{
$header = "GET / HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Connection: close\r\n\r\n";
fputs($fp, $header);
while (!feof($fp))
{
$str .= fgets($fp, 1024);
}
fclose($fp);
return (strpos($str, $find) !== false);
}
}
function alert($host)
{
// mail('wjydream@163.com', 'JK3ing', $host.' down');
}
$host = 'www.banmacar.com';
$find = 'username';
echo "应用服务器APACHE车务平台HTTP状态...";
if (!check($host, $find))
alert($host);
$url = 'https://www.banmacar.com/common/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch) ;
echo $rescode;
echo "<br>";echo "<br>";
echo "<a href='https://www.banmacar.com/jk2.php'>更多探针监控</a>";
echo $res;
$find = 'username222';
if (strpos($res, $find) !== true) {
alert($host);
//mail('wjydream@163.com', 'JK3ing', ' down');
}
?>