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/jk1.php

34 lines
945 B

<?php
if($fp = @fopen('/proc/loadavg', 'r')) {
list($loadaverage) = explode(' ', fread($fp, 6));
echo 'loadaverage:';
echo $loadaverage;
fclose($fp);
if($loadaverage > 2) {
header("HTTP/1.0 503 Service Unavailable");
echo 'server die ';
exit();
}
}
/**
* 记录服务器负载、内存使用、cpu状态,交换分区
* 每10秒检测一次<EFBFBD>
*/
//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);
// sleep(10);
//}
?>