";echo "
";echo "
"; if($fp = @fopen('/proc/loadavg', 'r')) { list($loadaverage) = explode(' ', fread($fp, 6)); echo '系统服务器47.98.20.102负载压力 loadaverage:'; echo $loadaverage; echo "
"; 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').'
CPU:'.$cpu.'
内存MEM:'.intval($mem/1024).'
交换分区SWAP:'.intval($swap/1024).chr(10); echo "
"; echo "
"; echo "Apache服务器httpd用户进程数:"; $cpu2=passthru('ps -efw|grep httpd|wc -l'); echo $cpu2; echo "
"; 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 "
";echo "
"; echo "更多探针监控"; echo $res; $find = 'username222'; if (strpos($res, $find) !== true) { alert($host); //mail('wjydream@163.com', 'JK3ing', ' down'); } ?>