note 109451 added to function.sys-getloadavg
| From: | vladvarna at gmail dot com | Date: | Wed, 18 Jul 2012 14:51:51 +0000 |
| Subject: | note 109451 added to function.sys-getloadavg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189280@lists.php.net to get a copy of this message | ||
You can emulate loadavg using this. Can also be used to get iowait
function ProcStats()
{
$fp=fopen("/proc/stat","r");
if(false===$fp)
return false;
$a=explode(' ',fgets($fp));
array_shift($a); //get rid of 'cpu'
while(!$a[0])
array_shift($a); //get rid of ' '
var_dump($a);
fclose($fp);
return $a;
}
$a=ProcStats();
sleep(5);
$b=ProcStats();
$total=array_sum($b)-array_sum($a);
$loadavg = round(100* (($b[0]+$b[1]+$b[2]) - ($a[0]+$a[1]+$a[2])) / $total, 2); //
user+nice+system
$iowait= round(100* ($b[4] - $a[4])/$total,2);
----
Server IP: 69.147.83.197
Probable Submitter: 89.38.142.227
----
Manual Page -- http://www.php.net/manual/en/function.sys-getloadavg.php
Edit -- https://master.php.net/note/edit/109451
Del: integrated -- https://master.php.net/note/delete/109451/integrated
Del: useless -- https://master.php.net/note/delete/109451/useless
Del: bad code -- https://master.php.net/note/delete/109451/bad+code
Del: spam -- https://master.php.net/note/delete/109451/spam
Del: non-english -- https://master.php.net/note/delete/109451/non-english
Del: in docs -- https://master.php.net/note/delete/109451/in+docs
Del: other reasons-- https://master.php.net/note/delete/109451
Reject -- https://master.php.net/note/reject/109451
Search -- https://master.php.net/manage/user-notes.php