Website statistics
How to enable awstats
By default, DirectAdmin comes with webalizer stat software, but it is possible to switch to awstats. Just be aware it is a global on/off switch and not per domain.
If you wish to enable this feature for testing or use, you must install awstats. Type:
da build set awstats yes
da build awstats
This will do several things.
- download and install the awstats setup
- add awstats=1 to your directadmin.conf
- add webalizer=0 in your directadmin.conf (webalizer will be shut off, but you can override it if you want both)
NOTE: due to the way the log names are set up in config files, the rotation of Apache logs will be slightly different during the tally. Before the tally, all logs will not be renamed to .log.1. Logs will be processed in place.
This has side effects in that a HUP is not going to be sent to the master httpd process right before the tally. During the rotation for each user, logs will simply be truncated instead of deleted (as they always have been for single-user tallies). Testers should keep an eye on the effects of truncating a live log without the instant Apache restart. Likely it will be fine. Also Apache is restarted post tally as usual anyway.
Awstats are placed as static HTML pages into:/home/user/domains/domain.com/awstats
The config and tally data are stored in:/home/user/domains/domain.com/awstats/.data
The advantage of having the data under /home/user
, is that users can bring it with them when their accounts are moved around.
The benefit of the integrated awstats over many plugins is the security. Some awstats plugins use chmod 777 for many files and folders, meaning anyone on the system has the ability to change things around. With this setup, files are chown'd to root, and chmod to a minimal setting, thus things are safe, secure, and private.
Like webalizer, with this setup, subdomains will have their own awstats page.
DirectAdmin will also parse the awstats data files to grab the bandwidth for the subdomains, so as long as the awstats are being processed for those subdomains, the bandwidth for each subdomain will show up in DA on the subdomains page (just like it did for webalizer, using the webalizer stats).
Lastly, the ../stats symbolic link on the domain stats page will point to ../awstats if the link is created (instead of the ../stats with webalizer).
Awstats could be disabled via the GUI in their account settings or in the user.conf
file, which overrides the global enable:
awstats=0
How to customize the output of webalizer
DirectAdmin uses the default webalizer settings by not specifying a webalizer.conf file at all. If you want to adjust the settings for webalizer, you can create your own basic webalizer.conf file for DA to use. This file must be domain-independent because this one file will be used for all domains without any modifications to it.
Create the /usr/local/directadmin/data/templates/custom/webalizer.conf
and add the custom settings you wish to use to that directory.
Example of "webalizer.conf" file to do reverse IP lookups:
DNSCache /var/lib/webalizer/|DOMAIN|.dns_cache.db
DNSChildren 10
Also you need to set the proper permissions/ownerships for that file:
chown root:root /var/lib/webalizer
chmod 1777 /var/lib/webalizer
You may use tokens in that file:
https://www.directadmin.com/features.php?id=483
https://www.directadmin.com/features.php?id=430
Manually "webalizer" can be run in this way, using Apache as WEB service:
- without custom file:
webalizer -p -n [DOMAIN] -o /home/[USER]/domains/[DOMAIN]/stats /var/log/httpd/domains/[DOMAIN].log
- with custom file:
webalizer -c /usr/local/directadmin/data/templates/custom/webalizer.conf -p -n [DOMAIN] -o /home/[USER]/domains/[DOMAIN]/stats /var/log/httpd/domains/[DOMAIN].log
or even better it s recommend to run this command for 1 user:
echo "action=tally&value=[USER]&type=user" >> /usr/local/directadmin/data/task.queue
To read the created "[DOMAIN].dns_cache.db" file we can use this command:
db_dump /var/lib/webalizer/[DOMAIN].dns_cache.db
How to enable country stats in awstats
Although there are more complex/recommended ways of enabling country stats in awstats (the geoip plugin), a very quick and easy way to enable basic country stats in awstats is to edit /home/username/domains/domain.com/awstats/.data/awstats.domain.com.conf
and set:
DNSLookup=1
Note that this will likely slow down the computation of stats significantly, since many reverse IP lookups would need to be done. With that option, the visitor IPs should have a PTR record, and based on it, a country TLD is detected (if the TLD is anything other than .com/.org/.net).
As of 2019, the below guide is not factual as Maxmind dropped support for GeoIP v1.
A better method for doing the Country stats is to use the GeoIP plugin. A very rough guide would be as follows (beyond our support):
- Install GeoIP data:
wget http://maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar xvzf GeoIP.tar.gz
cd GeoIP*
./configure
make
make install
- Install perl module:
cpan -i Geo::IP
- Edit the domain's awstats conf file
/home/username/domains/domain.com/awstats/.data/awstats.domain.com.conf
and set:
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
You can leave the other setting as DNSLookups=0
.
If you'd like to have default values for your new domains, the template can be found here: /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf
.
On the first run of AwStats, this will will be copied over. This template is not used for existing domains, only new domains.
How to rebuild awstats static .html for previous months
Assuming the data for the required months does exist in /home/username/domains/domain.com/awstats/.data
, you should be able to regenerate your static HTML pages for those months. The script below can do it for you. Create old_awstats.sh with content:
#!/bin/sh
if [ "$#" -eq 0 ]; then
echo "Usage:";
echo " $0 <MM> <YY>";
exit 1;
fi
month=$1
short_year=$2
full_year=20${short_year}
for u in `ls /usr/local/directadmin/data/users`; do
{
for d in `cat /usr/local/directadmin/data/users/$u/domains.list`; do
{
echo "";
echo "$u: $d: $month $full_year";
DATA=/home/$u/domains/$d/awstats/.data/awstats${month}${full_year}.${d}.txt
if [ ! -s $DATA ]; then
echo "Cannot find $DATA for $month $full_year. Skipping.";
continue;
fi
/usr/bin/perl /usr/local/awstats/tools/awstats_buildstaticpages.pl \
-config=$d -configdir=/home/$u/domains/$d/awstats/.data -update \
-diricons=icon -awstatsprog=/usr/local/awstats/cgi-bin/awstats.pl \
-dir=/home/$u/domains/$d/awstats -builddate=${short_year}${month} \
-year=$full_year -month=$month
echo "";
}
done;
}
done;
exit 0;
Save and make it executable:
chmod 755 old_awstats.sh
Run it for each month, for example, April (month 04) 2020:
./old_awstats.sh 04 20
CageFS with awstats, no update: Can't open perl script
If your awstats are not working with CageFS and you're getting an error like this when testing it manually:
# ./awstats_process.sh user domain.com
Conversion not required. Continuing normally
Can't open perl script "/usr/local/awstats/tools/awstats_buildstaticpages.pl": No such file or directory
Cleanup...
it likely means the data has not been copied over to the skeleton folder in /usr/share/cagefs-skeleton/usr/local/
.
To get around that, edit /etc/cagefs/conf.d/directadmin.cfg
and add 2 values, so beginning of the line looks like this, assuming awstats-7.7:
paths=/usr/local/awstats/, /usr/local/awstats-7.7/, /usr/local/awstats, /usr/local/php....
Then run:
/usr/sbin/cagefsctl --force-update
which should copy everything over to the cagefs-skeleton/usr/local path. Just confirm it:
# ls -la /usr/share/cagefs-skeleton/usr/local
total 40
lrwxrwxrwx 1 root root 11 Jun 26 22:57 awstats -> awstats-7.7
drwxr-xr-x 5 root root 4096 Mar 1 2016 awstats-7.7
...
We add
- the literal awstats-7.7 directory
- the literal path to the awtstats link (without trailing slash)
Not sure if there was a change in CageFS and older version of CafeFS, but it seems they've fixed a bug to prevent us from doing it the old way. 😃