I am looking for an application performance management for PHP (see http://en.wikipedia.org/wiki/Application_performance_management)
This tool could be plugged to any PHP application in production, and can collect/display statistic about PHP execution time, network time, db query time for each request. For each indicator, I would like to see the min, max and average value.
All these statistics would be available in real time and also for the past.
Is there any existing tool which can do that? Suggestion for any tools (free or not) are welcome.
(/me takes a deep breath)
Lets deal with this one line at a time:
application performance management for PHP (see ...
You're probably not going to get very sensible answers from people who don't know what APM is.
This tool could be plugged to any php application in production
This rather implies you are looking for a PHP code solution - that's probably the last way you should attempt to solve the problem.
statistic about php execution time
OK, the only place you can reliably measure this is within the PHP code - but its a crappy way to solve the problem.
network time
Which network time? There's at least 2 round trips before the response starts to come back to the client, neither of which PHP can see. Also you can't measure the delay between completion of the PHP script and the final ack (or RST) from the client.
db query time
This is getting outside the scope of APM.
Just to find out what you need, and what you can capture would require much more in-depth analysis than can be provided here. However I would recommend that you do not try to instrument your code to get these metrics.
A lot of the information can be captured by the webserver - assuming its Apache, do ensure that you are logging %D and %X.
One of the best approaches to solving the problem is by packet sniffing. If you've not got the budget for something like Client Vantage or Nimsoft's solutions, you might want to have a look at Pastmon.
Although the more expensive of these claim to be able to reconstruct page turn response times, my experience is that they often have problems with anything other than plain static content. Throw a PRG pater at them and they get completely lost.
If you want to measure page turn response, then there are 2 approaches
use log analysis (do set up mod_usertrack for Apache if you don't already have some user tracking functionality - and enable the corresponding user and mime logging) then you can get an estimate of page turn times from the start of the 'text/html' request to the end of the last non-'text/html' request. Unfortunately I am not aware of any off-the-shelf package which provides this kind of analysis.
push the timing out onto the browser using javascript. This is how Oracle's EUPM works - but you'll need to be running an Oracle stack with a full Grid Control installation to see the results. But do have a look at Episodes for the bones of a very promising architecture (remarkably Microsoft have invented something which looks remarkably similar!) - when I win the lottery and retire I might try building support for Episodes into Piwik for a hobby.
While there are lots of people willing to sell you packages which do all the above, in a lot of cases there are some semantic differences between what they actually provide and what you are measuring. E.g. a lot of them assume that server side processing completes when the server begins the response - which is patently nonsense, although it can be treated as a consistent indicator of the state of the system (see also mod_log_firstbyte)
HTH
Take a look at NewRelic. It covers all of the information you're looking for. I don't have an exact independent measurement of overhead for the PHP stack, but I did extensive measurement of the java stack a little while back, and it was in the 2-5% range. PHP overhead is claimed by the company to be about the same, and I'd tend to believe them.
There's a wide range of APM tools and they all work differently and are capable of collecting different statistics. Here are some examples of how different tools work and why they might be more or less useful depending on what you're trying to monitor:
- Server-based agents. Allows collection of stats like CPU and memory load. See Splunk or Cacti.
- Web end-user monitors often work by including some JavaScript on the pages you serve up. I'm sure you can imagine there's plenty of statistics that can be gathered only from the within the end-user's browser.
- Code-level augmentation/reporting/analysis. For example, with .NET there's some tools for this from AVIcode.
- Network traffic analysis. Product quality varies by how much traffic it can handle and how many protocols are understood. There's a company called ExtraHop that has a product in this category. I believe that their technology powers http://www.networktimeout.com where you can upload a packet dump for analysis.
For profiling PHP applications, you might want to check out XHProf:
http://pecl.php.net/package/xhprof
http://techportal.inviqa.com/2009/12/01/profiling-with-xhprof/
精彩评论