How to get CPU usage and RAM usage without exec?

前端 未结 5 2051
日久生厌
日久生厌 2020-11-28 05:19

How does VBulletin get the system information without the use of exec? Is there any other information I can get about the server without exec? I am interested i

5条回答
  •  無奈伤痛
    2020-11-28 05:26

    after searching on forums and trying many methods, best accurate is this:

    $stat1 = file('/proc/stat'); 
    sleep(1); 
    $stat2 = file('/proc/stat'); 
    $info1 = explode(" ", preg_replace("!cpu +!", "", $stat1[0])); 
    $info2 = explode(" ", preg_replace("!cpu +!", "", $stat2[0])); 
    $dif = array(); 
    $dif['user'] = $info2[0] - $info1[0]; 
    $dif['nice'] = $info2[1] - $info1[1]; 
    $dif['sys'] = $info2[2] - $info1[2]; 
    $dif['idle'] = $info2[3] - $info1[3]; 
    $total = array_sum($dif); 
    $cpu = array(); 
    foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 1);
    print_r($cpu);
    

提交回复
热议问题