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

5 years ago
<?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();
}
}
/**
* <EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD><EFBFBD>ڴ<EFBFBD>ʹ<EFBFBD>á<EFBFBD>cpu״̬,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ÿ10<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><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);
//}
?>