ChickenSteak
12-08-2002, 10:44 PM
Hello, I'm just wondering if anyone has an simple easy solution to checking if a servers load is below or equal to .50 using the "uptime" command.
Edit: Using php btw.
Edit: Using php btw.
![]() | View Full Version : Server Load Checking ChickenSteak 12-08-2002, 10:44 PM Hello, I'm just wondering if anyone has an simple easy solution to checking if a servers load is below or equal to .50 using the "uptime" command. Edit: Using php btw. sasha 12-08-2002, 11:22 PM // this is what you are checking $crit = 0.50 ; // could use uptime, but then would need to // use brain to split it. This is the same, almost ;P $c = `cat /proc/loadavg`; $u =explode (" ",$c,5) ; // this is for last minute. //use $u[1] for 5 min interval, and $u[2] for 15 minutes interval $upt =$u[0] ; if ($upt < $crit) { // do stuff echo "Yes, yeess, yeeeess !!!\n" ; } JustinH 12-08-2002, 11:27 PM Agreed, the above method is much easier... if you want to use the uptime command you can do this (didn't bother testing... should work). Keep in mind there is probably an easier way but I just threw this together. <?php $uptime = exec('uptime'); $uptimeArray = split(",", $string); array_reverse($uptimeArray); array_pad($uptimeArray, 3); foreach($uptimeArray as $uptime) { trim($uptime); if ($uptime => .50) { echo "Loadtime is " $uptime; } else { echo "Loadtime is fine"; } } ?> JustinH 12-08-2002, 11:29 PM I'm a dork :p... you'd have to add a $uptime = str_replace("load average:", "", $uptime); right after the exec command. :). Like sasha said, cating the loadavg file is much faster (and easier). ChickenSteak 12-08-2002, 11:41 PM Ok now that, thats that how would I make it loop checking every 15 seconds or so if the first time it checks it isn't 50 or below, and to keep looping untill it's 50 or below. JustinH 12-09-2002, 01:24 AM With Cron... but you don't want to do that. That will spike your 1 minute load times. On a live server that'd probably keep them at above .50 if avg load times are very high. Besides, .50 isn't great but it certainly isn't that bad. Mbarb 12-09-2002, 08:17 PM will this help http://www.webhostingtalk.com/showthread.php?s=&threadid=77792 |