I'm supprised you don't have the /proc/loadavg. I assume you tried "cat /proc/loadavg" ?
Either way, the server may not have permissions to access that file.
Here is a new way of formatting the output of "uptime" to get the load averages.
PHP Code:
<?php
$os = strtolower(PHP_OS);
if ( $os !== 'winnt' AND $os !== 'win32' )
{
$data = exec('uptime');
$load = explode(' average: ', $data);
$load_each = explode(', ',$load[1]);
echo "Real: {$load_each[0]}, User: {$load_each[1]}, Sys: {$load_each[2]}";
}
?>
Provided you are on linux and are able to run "uptime" this will work for you.
But it looks like you can't run the exec command. Try to write a bash script to dump the output of uptime into a file, and read the file.
bash script:
Code:
#!/bin/bash
uptime > /wwroot/load_averages.txt
Add that to your crontab to run every X minutes
Then replace the $data = exec('uptime') with $data = file_get_contents('load_averages.txt')
That will look something like this:
PHP Code:
<?php
$os = strtolower(PHP_OS);
if ( $os !== 'winnt' AND $os !== 'win32' )
{
$data = file_get_contents('load_averages.txt');
$load = explode(' average: ', $data);
$load_each = explode(', ',$load[1]);
echo "Real: {$load_each[0]}, User: {$load_each[1]}, Sys: {$load_each[2]}";
}
?>
The load_averages.txt will need to be in the same directory as this current php file, or change the path.
Hope this helps
Both work on my Slackware 10.2 server running php 4.1