Bandwidth/traffic stats

So… im corious to know.. im running a few websites in a shared hosting kind of format for some people, inwhich im running apache2/php/jsp and mail/ftp.

Some of them are interested to know what and/or howmuch they have transfered from there site, is there any easy way of tracking this kind of information?

the sites are all virtual hosts in apache2.. so i was thinking is there any kind of traffic accounting module for apache?

cheers

Nathan

6 Replies

AWStats and Webalizer do what you're looking for.

these packages seemed quite interesting to configure.. anyone have a really decent tutorial for setting them up with virtual hosting in place?

cheers

NF

I use the following, & process using webalizer:

ServerRoot "/www"

LogLevel warn

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

ServerName www.mysite.com

ServerAlias mysite.com

Options +Indexes

ServerAdmin webmaster@mysite.com

DocumentRoot /home/mysite/www

CustomLog logs/access_log combined

puts log file in /www/logs/access_log

I use AWStats along with separate log files for all my vhosts. You should be able to do it with one log file, but if you miss a configuration option, you're going to get vhost statistics mixed in with other vhosts. There is a big drawback to my setup though. If you have lots of vhosts, this isn't going to work for you, Apache will lock up opening too many file descriptors on log files. With fair warning out of the way…

In Apache config, if it isn't already setup, you'll want to let Apache know to not log virtual hosts to your main log file and also a logformat describing the format to log to for AWStats (my config uses the standard NCSA combined log format, it might already be configured in your Apache config):

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog logs/access_log combined env=!VLOG

Then in each of your virtualhost definitions (depending on where you want to see your logs):

CustomLog logs/access_log_myvhost combined

The rest of the setup is croning AWStats to run whenever you want stats updated (the more often the better since AWStats knows where it left off in the log files, and can spread out it's work load, especially if you enable DNS lookups, not advisable on high traffic sites).

In your AWStats config files, the variables you'll want to make sure you've set are:

LogFile="/var/log/apache2/access_log_myvhost"
LogType=W
# Here's where that NCSA standard comes in handy, you
# don't have to specify you're entire custom format since
# AWStats has a setting for the standard.
LogFormat=1
SiteDomain="mydomain.tld"

So long as you have those ones set right, you should be fine, but it's always a good idea to go through the entire config file of course. The important settings should be right up top.

@tierra:

I use AWStats along with separate log files for all my vhosts. You should be able to do it with one log file, but if you miss a configuration option, you're going to get vhost statistics mixed in with other vhosts. There is a big drawback to my setup though. If you have lots of vhosts, this isn't going to work for you, Apache will lock up opening too many file descriptors on log files. With fair warning out of the way…

Yeah, I've run into that before. The good news is that it can handle several hundred open files. If you have an access log, error log, and SSL log for each vhost, you can probably get upwards of about a hundred domains or so before it crashes and burns.

If you only use maybe 20 vhosts, there's no problem at all.

Well, part of the problem is when you get concurrent connections with the same vhost, you can have a few threads with the same vhost log file open, so you get into some multiplication problems at that point being that's where it starts to have real problems even if you only had 20 vhosts, but they have a lot more traffic. At least that's been my understanding of it, someone correct me if I'm wrong.

That's also part of the reason I kill logging to the main access log file as well since it would double the file descriptors open with both a separate vhost log file and main access log file.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct