Please Login First!"; exit(1); } $memory=array(); exec("free -m|awk '{print $2 }'|tail -2",$memory); $total_mem=$memory[0]; $total_swap=$memory[1]; $delay=2; $logfile="/dev/shm/".basename(__FILE__,"php")."log"; $history=@file_get_contents($logfile); if($history!=""){ $history=json_decode($history); }else{ $history=array(); } $HL=count($history)-1; if($HL>=0){ $info=$history[$HL]; } if(function_exists('system')){ date_default_timezone_set("PRC"); if($HL<0||(isset($history[$HL][4]) && $history[$HL][4] <= (time()-$delay)*1000) ){ $info=array(); // system(" top -bn1 | grep \"Cpu\" | awk -F, '{print $4}' | awk '{print 100-$1}' "); exec(" top -bn1 | grep \"Cpu\" | awk -F, '{print $4}' | awk '{print 100-$1}' ",$info); $info[count($info)-1]=floatval($info[count($info)-1]); exec("free -m|grep Mem|awk '{print $7 }'",$info); $info[count($info)-1]=floatval($info[count($info)-1]); exec("free -m|grep Swap|awk '{print $3 }'",$info); $info[count($info)-1]=floatval($info[count($info)-1]); exec("netstat -s |grep 'connections established'|cut -d\ -f5",$info); $info[count($info)-1]=floatval($info[count($info)-1]); array_push($info,(time())*1000); exec("df -m|grep '/dev/vda3'|grep -v 'shm'|awk '{print $3 }'",$info); $info[count($info)-1]=floatval($info[count($info)-1]); exec("df -m|grep 'aliyun'|grep -v 'shm'|awk '{print $3} '",$info); $info[count($info)-1]=floatval($info[count($info)-1]); //echo json_encode($info); array_push($history,$info); while(count($history)>900) array_shift($history); file_put_contents($logfile,json_encode($history)); // echo json_encode($history); } $chart_cpu=array(); $chart_mem=array(); $chart_swap=array(); $chart_tcp=array(); foreach($history as $sample ){ array_push($chart_cpu,array($sample[4],$sample[0])); array_push($chart_mem,array($sample[4],$sample[1]/$total_mem*100)); array_push($chart_swap,array($sample[4],$sample[2]/$total_swap*100)); array_push($chart_tcp,array($sample[4],$sample[3]/2)); } if(isset($_GET['json'])){ echo json_encode(array($chart_cpu,$chart_mem,$chart_swap,$chart_tcp)); exit() ; }else{ $AG=array("_",".",":","i","!"); $HL=count($history)-1; $cpu_ag=""; $al=9-strlen(strval($info[0])); if($HL>$al){ for($i=$al;$i>=0;$i--){ $cpu_ag.= $AG[intval(log($history[$HL-$i][0],3))]; } } ?>

CPU :
FREE:M
SWAP:M
TCP :pairs
DISK:M
NAS :G

loading data ...