开发者

PHP gather server statistics

I am building a custom component for my webapp that will benchmark e开发者_运维知识库ach service, so far the plan is to benchmark the usual stuff:

  • Response Time
  • Memory
  • Current server activity

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?


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)


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜