Plesk 8.3
awstats only shows the current month’s log statistics. The monthly history from previous months is forgotten.
Cause:
Awstat’s configuration files all point to a working directory of $DOMAIN_STATS/webstat/current. There is a daily job which calculates the web activity and places the results into that directory. The “current” directory is actually a symbolic link to a real directory called $DOMAIN_STATS/webstat/YYYY-MM, where YYYY-MM is year-month.
On the 1st day of the month another program creates a fresh folder called YYYY-MM and makes the “current” link point to this instead. This new directory is empty and so the “current” directory has no history in which to draw last months statistics.
The rotation program runs at about 4am, which means that activity from 0:00 to 4:00 are trapped in the previous months activity folder.
Solution:
After creating the new month folder, the
Plesk program should copy the previous months activity files into the new folder.
This problem is known to
Plesk but their 8.4 release was a bit of a disaster and had to be withdrawn, but as I understand this issue is not fixed in 8.4 either.
One of the nice things about
Plesk is that all its system maintenance scripts are written in PHP instead of the local shell. This is almost certainly because it can use the same scripts on Unix and Windows, so it removes the need to write batch files in bash and MS-DOS.
The problem with
Plesk is that it obfuscates the PHP files preventing them from being read in the same way as a normal (text) PHP file. This makes it especially hard to navigate through the
Plesk system maintenance files.
As a result of this, there is a maze of unreadable cron (and anacron) configuration files hiding the
Plesk add-on program that makes the “current” folder point to a new YYYY-MM folder.
If anyone knows where this program is, please add a comment below.
I do know that it finishes at about 6am with a new empty directory for this month with no statistics files in it. I can tell the cron to run my plesk-awstats-fixer.sh program to run any time before
awstat gets run for the second day’s statistics.
0 10 1 * * plesk-awstats-fixer.sh > paf.out 2> paf.err
#!/bin/bash
#
# This code was written by BigSoft Limited.
# Please include this message when you use the code in any form.
# Code comes as is and without warrenty
#
# David Newcomb (c) BigSoft Limited 2008
#
# Get MySQL's admin password
PSA_PW=`cat /etc/psa/.psa.shadow`
PSA_USER=admin
# Location of webstats folders
VHOST=/var/www/vhosts
STATS=statistics/webstat
# Find enabled domain names that use awstats statistics.
# When a client is deactivated the status of a domain
# becomes non-zero, so there is no need to join on the
# client's table.
SQL=" SELECT d.name"
SQL="$SQL FROM domains d, hosting h"
SQL="$SQL WHERE d.id = h.dom_id"
SQL="$SQL AND d.status = 0"
SQL="$SQL AND h.webstat = 'awstats'"
# Run SQL
DOMAINS=`mysql --skip-column-names -u$PSA_USER -p$PSA_PW -e"$SQL" psa`
for DOMAIN in $DOMAINS
do
AWSTATS_DIR=$VHOST/$DOMAIN/$STATS
echo "Checking $AWSTATS_DIR"
if [ ! -d "$AWSTATS_DIR" ]
then
echo "Sorry awstats folder does not exist: $AWSTATS_DIR"
continue
fi
cd $AWSTATS_DIR
CUR=`ls -l current`
YEAR_MONTH=${CUR:2-10}
MONTH=${YEAR_MONTH:6}
YEAR=${YEAR_MONTH:1:4}
# Sort out the number padding
if [ "$MONTH" = "01" ]
then
LAST_MONTH=12
LAST_YEAR=`expr $YEAR - 1`
else
LAST_MONTH=`expr $MONTH - 1`
if [ "$LAST_MONTH" -lt "10" ]
then
LAST_MONTH="0$LAST_MONTH"
fi
LAST_YEAR=$YEAR
fi
echo "Found $YEAR_MONTH $YEAR $MONTH => $LAST_YEAR $LAST_MONTH"
# Copy all the history files into place
echo "Copying $LAST_YEAR-$LAST_MONTH/awstats[012][0-9]$LAST_YEAR.$DOMAIN-http.txt"
cp -p $LAST_YEAR-$LAST_MONTH/awstats[012][0-9]$LAST_YEAR.$DOMAIN-http.txt current
done