Reputation: 971
I am building a custom component for my webapp that will benchmark each service, so far the plan is to benchmark the usual stuff:
etc.
I have built the basic stuff and i was thinking to store the output of the linux "top" command, which lists the current running processes and the amount of used resources. Though, i haven't been able to obtain any responde from running:
$output = shell_exec('top');
echo "<pre>";
var_dump($output);
echo "</pre>";
But other simpler commands do work, like the example in the php manual:
$output = shell_exec('ls -lart');
So my questions are: - Do I need to run the "top" command as root? (currently it runs under apache user) - Or are there any other php command that could help me get server statistics?
I read this post, but im not really interested in installing anything, as i need my stats on the demand and store them on my DB. PHP server statistics script?
Upvotes: 1
Views: 905
Reputation: 818
You could cat anything in the /proc directory like cat /proc/cpuinfo to get any CPU information about the server. Everything in linux can be reduced to the file system and any system statistics that you would ever want to find can be found in /proc (well almost all stats)
Upvotes: 2
Reputation: 19573
When your run top, you see that the program continues to execute, and does not stop. Its also interactive.
If you want to capture the output, you need to have a program the executes and then stops. There might be an option with top to do that. But most info can be gathered by other commands.
Run top like this:
top -b -n1
Upvotes: 2