Jump to content

Archived

This topic is now archived and is closed to further replies.

onlyican

Check Server Load

Recommended Posts

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
[code]
<?php $data = shell_exec('uptime'); $uptime = explode(' up ', $data);
$uptime = explode(',', $uptime[1]); $uptime = $uptime[0].', '.$uptime[1];
echo (''.$uptime.''); ?>
[/code]

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)

Share this post


Link to post
Share on other sites
This will get the server load.

[code]<?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}";
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.