PHP Code To Check Server Load

< ? php
$uptime = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs);
$uptime = explode(' up ', $uptime);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
$start=mktime(0, 0, 0, 1, 1, date("Y"), 0);
$end=mktime(0, 0, 0, date("m"), date("j"), date("y"), 0);
$diff=$end-$start;
$days=$diff/86400;
$percentage=($uptime/$days) * 100;
$load=$avgs[1].",".$avgs[2].",".$avgs[3]."";
echo 'Average Load: '.$load;
echo 'Uptime: '.$uptime;
?>


--
If you like this post please post your comment

No comments:

Post a Comment