Jump to content


Photo

Check Server Load


  • Please log in to reply
1 reply to this topic

#1 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 17 September 2006 - 10:08 PM

Hey guys

I want to monitor some tings on my server

Does anyone know how to check Server Load

I am running
php4.4.1
(and should be running 5.1.4 tomorrow)

I know how to check the Uptime
<?php $data = shell_exec('uptime'); $uptime = explode(' up ', $data); 
$uptime = explode(',', $uptime[1]); $uptime = $uptime[0].', '.$uptime[1]; 
echo (''.$uptime.''); ?>

But I want to check Server Load (Yes, the whole server)
and is it possible to monitor Bandwidth on a certain page as well
(maybe add a lil script which gets the server load, and stores to a DB or something)
Tell me the problem, I will try tell you the solution

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 18 September 2006 - 06:16 AM

This will get the server load.

<?php
$loadavg_file	= @file_get_contents('/proc/loadavg');
$loadavg_file	= explode(' ',$loadavg_file);
$loadavg		= trim($loadavg_file[0]);

if(empty($loadavg))
{
	$uptime_exec= explode(' ',@exec('uptime'));
	
	if(!empty($uptime_exec))
	{
		$loadavg= $uptime_exec[count($uptime_exec)-1];
	}
	else {
		$loadavg= '--';
	}
}

echo "Server load: {$loadavg}";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users