AWStats Totals with cPanel

For some time ago I wanted to see AWStats Totals with cPanel, so I could see the total amount of hits all websites, across a server received, but there wasn’t really a way to do it, until I found this awesome tool called ‘AWStats Totals‘. It’s a very simple PHP script, that reads the awstats files, and print out statistics like unique visitors, number of visits, pages, hits and bandwidth. It also allows you to select the month and year to view stats, and modifying the script a little, you’ll be able to read all files, since the beginning, providing total amount of hits, ever recorded by awstats. I think it’s pretty cool. But, since the script need a path where all the files are stored, we need to move those files to a folder so we can read it. I came up with following line of code, which will grep all awstats data that you need, and copy it to a folder.

cd /var/cpanel/users/; find * | while read CPUSER; do rsync /home/${CPUSER}/tmp/awstats/awstats*.txt /root/awstats_files/ 2> /dev/null; done;

The code is pretty simple, it cd into the /var/cpanel/users dir, it find all files in the directory, and read all of them, then it does a simple rsync command to grep the awstats*.txt files from the users awstats directory and copy it to /root/awstats_files as an example. The reason why I did choose to use rsync is because we’ll run the script every 24 hours, and instead of copying already existing files, it will only copy new files, since it’s just internal transfer I don’t parse any arguments to rsync, because I didn’t really see the need of it. When you load the awstatstotals.php script, it should look something like this: awstats-totals
By default it will order by bandwidth, but you can sort by hits, pages, visits and unique visitors. So if you want to get very basic statistics about traffic received on a server, this tool might be helpful. Keep in mind, the stats is based on AWStats, so if you don’t have AWStats enabled on the server, it won’t work. But it should be pretty precise, because AWStats is parsing the access logs from the server. I’m happy to hear, if any other have solutions to get these kinds of statistics in a nice way!