Applicable to:
- Plesk Onyx for Linux
Question
How to recalculate AWStats web-statistics using domain logs for previous months?
Answer
There are two techniques to recalculate/regenerate AWStats statistic files:
-
From AWStats txt files, which are still within the AWStat directory:
Instructions to check-
Connect to the server via SSH.
-
Check the directory:
# ls -lahn /var/www/vhosts/system/example.com/statistics/webstat-ssl/ | grep awstats | awk '{print $9}'
awstats082018.example.com-https.txt
awstats092018.example.com-https.txt
awstats102018.example.com-https.txt
awstats112018.example.com-https.txt
awstats122018.example.com-https.txt
Note: In this case the months 08(August), 09(Semptember), 10(November), 11(October), 12(December) can be retrieved for the year 2018.
-
-
From the old logs, which are present on the server.
Note: In both, old logs and AWStats txt file, are deleted, the recalculation will not be possible.
Installation
-
Connect to a Plesk server via SSH.
-
Download and unpack the script:
# wget https://support.plesk.com/hc/en-us/article_attachments/360015808219/rebuild_awstats.tar.gz
# tar -xzvf rebuild_awstats.tar.gz
-
For Ubuntu 14.04, a symbolic link should be created:
# ln -s /usr/lib/plesk-9.0/logresolvemerge /usr/share/doc/awstats/examples/logresolvemerge.pl
-
-
Run this command to show help message:
# ./rebuild_awstats.sh
Rebuild AWstats static pages from available log files.
Usage: ./rebuild_awstats.sh [options] [<domains...>]
Options:
-A
--all-domains
Process all domains. If this option is not specified, then list of
domains to process must be provided.
-F
--from-scratch
Remove contents of webstat/ and webstat-ssl/ directories before
rebuilding statistics pages (originals are saved with numeric
suffix). Statistics will be rebuilt from logs only, only for
period covered by log files. If this parameter is not used, then
statistics is recalculated beginning on the month on which log files
start (if log starts in the middle of the month, then statistics
for first half of the month will not be present.)
-R
--rebuild
Rebuilds the HTML files for AWStats.
-h
--help
This message.
Click on a section to expand
-
General Functionality
-
For each specified domain (or all domains, if the -A option is used), the script will memorize the log file's start date.
-
Then, it will remove AWStats data files for the months covered by the log files and rebuild them with corresponding information.
-
Finally, the script will build static pages with statistics summary for each month covered by the log files.
-
-
-F
If the -F option is used, all AWStats data will be removed and new files will be generated using only the information stored in the log files. -
-R
if the -R option is used, the script will gather all data of the mentioned domain and will generate all months, where the AWStats txt data is existing. -
Merging Web-Statistics
In order to merge web-statistics which was created from scratch with AWStats statistics from another directory, the corresponding .txt file should be copied from the
webstat
directory. For example, statistics of a domain for December were created from scratch. In this case, the following files should be copied from/var/www/vhosts/system/example.com/statistics/webstat/
:- A .txt file dated by December 2018:
awstats122018.example.com-http.txt
At the end it required to run the script with -R to build the HMTL files:
# ./rebuild_awstats.sh -R example.com
- A .txt file dated by December 2018:
Click on a section to expand
For every processed domain, the script will report this message:
CONFIG_TEXT: === example.com
Saving: webstat* --> webstat*.3
Logs begin on Apr 18 2018
access_log* (new/old/corrupted): 9/0/0
access_ssl_log* (new/old/corrupted): 71/0/0
Rebuilding static pages: 2018-04 2018-05 2018-06 2018-07
The message "_Saving: webstat* --> webstat*.3 _" in the output above shows that the original directories are saved with a numeric suffix (the suffix is increased if the destination directory already exists). This makes it possible to roll-back to old AWStats statistics if needed.
In case the script was launched to recalculate statistics from scratch (with -F flag), which removes old web-statistics that is not stored in log files, it is possible to restore it from the backup that was created by the script.
Comments
6 comments
Not working when vhosts place is changed!
ls: cannot access '/var/www/vhosts/system/exmple.com/statistics/webstat*/': No such file or directory
ls: cannot access '/var/www/vhosts/system/example.com/statistics/webstat*/': No such file or directory
Hello Fouad Ahmed Fouad,
Thank you for bringing our attention to this fact. The script was modified to follow the virtual hosts' location replacement.
Hello,
This link is not active.. https://support.plesk.com/hc/en-us/article_attachments/360040067853/rebuild_awstats.tar.gz
We found error when wget from that link.
@Linux,
Here is the correct link: https://support.plesk.com/hc/en-us/article_attachments/360015808219/rebuild_awstats.tar.gz
The article has been updated. Thanks for noticing!
This tool does NOT seem to re-generate the
/usr/local/psa/etc/awstats/awstats.sitename-*.conf
files.. So the changes we make to the conf are not propaged to the site-specific config pages.Which, I suspect is the reason why people would want to use this tool mainly.
Any ideas how to incorporate the regeneration of the /usr/local/psa/etc/awstats/* pages into this tool?
Any ideas how to circumvent this problem?
Please sign in to leave a comment.