Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am interested in trying to get a side by side usage comparison of all the virtual hosts being served up by my apache server.

In the simplest case, I want to see a list (or bar chart) with each virtual host and the number of requests/traffic on that site.

I've been playing around with webalyzer and awstats but I haven't been able to compare multiple virtual hosts in the same infographic.

Anyone have any suggestions on tools for doing this (or how I might use the above tools to do so)?

share|improve this question

3 Answers 3

Well generally when using virtual hosts I have different access logs for each virtual host. If this is the case and you just want hits:

wc -l foo_vhosts.access*

This counts the lines, which would be log entires, which is basically how many hits you got. But you should describe if you log to different files or not, and post an example log entry.

If you don't log to different files, and your logging format doesn't include %v in its format, you are kind of out of luck, unless you can correlate each uri to its virtual host.

share|improve this answer
    
I am actually logging to separate files, so the wc output gives me a reasonable top level view However, I was hoping to get a slightly more detailed view into how things break down, and I'd like to be able to do some visualization on this. I was hoping there was a log analysis package that parsed your log files and turned them into graphs. In other words - how can I do what webalizer/awstats does, but using a composite multi-site breakdown. –  shreddd May 26 '10 at 2:16

First you need to change your log format so the virtual host is recorded in each log entry. Something like the following will get you a Combined/Expanded format with the bonus of %v which is the virtual host name:

LogFormat "%h %v %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" LogServerName

Then when you must tell apache to use this log format. Something like the following can be added globally or to the individual virtual hosts (easier globally). In fact I usually have the above line and this one in a single file called /etc/httpd/conf.d/access_logging.conf:

CustomLog /var/log/httpd/global_access.log LogServerName

Once that is done, you will at least be able to key off of different Virtual Hosts. Then you can use something like petit or uniq to do the following.

cat /var/log/httpd/global_access.log | awk '{print $2}' | petit --hash

Also, you could use racecar to do bandwidth analysis with something like this. It might be a bit slow on large files, but it is quick and dirty.

for i in `cat /var/log/httpd/global_access.log | awk '{print $2}'`; do cat /var/log/httpd/global_access.log | grep $i | racecar; done

Link: http://crunchtools.com/software/petit/ Link: http://crunchtools.com/software/racecar/

share|improve this answer

@kyle, cut -f 1 -d ' ' combinedlog|sort|uniq -c|sort -nr

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.