Recalculating Statistics for Previous Months

By default, Plesk utilities present only the current month's statistics in HTML format. You can retrieve HTML statistics for previous months using the AWstats utility. To do this, restore traffic usage information from logs and run the utility manually. Detailed instructions are provided below.

To recalculate statistics for previous months:

  1. Define the required environment variables by running the commands:

    export vhost_name=<domain_name>

    export AWSTATS_BIN_D=`grep ^AWSTATS_BIN_D /etc/psa/psa.conf | awk '{print $2}'`

    export HTTPD_VHOSTS_D=`grep ^HTTPD_VHOSTS_D /etc/psa/psa.conf | awk '{print $2}'`

    export PRODUCT_ROOT_D=`grep ^PRODUCT_ROOT_D /etc/psa/psa.conf | awk '{print $2}'`

    export awstats=${AWSTATS_BIN_D}/

    export awstats_gen_opts="-staticlinks -configdir=${PRODUCT_ROOT_D}/etc/awstats -config=${vhost_name}-http"

  2. Remove *.txt files from the $HTTPD_VHOSTS_D/system/<domain_name>/statistics/webstat directory by running the command:

    find $HTTPD_VHOSTS_D/system/$vhost_name/statistics/webstat -name '*.txt' -exec mv '{}' '{}'.orig \;

  3. Analyze the domain log files with awstats by running the command:

    $awstats $awstats_gen_opts -LogFile=$HTTPD_VHOSTS_D/system/${vhost_name}/statistics/logs/access_log.processed

    This command creates subdirectories with the names "YYYY-MM" in the $HTTPD_VHOSTS_D/system/<domain_name>/statistics/webstat directory. "YYYY" and "MM" show the year and the month in which the corresponding statistics were collected.

    If you want to rebuild statistics pages for a long period, you should start recalculation from the earliest log files. For example, if you have set the number of log files to 10 analyze files in the following order: access_log.processed.10, access_log.processed.9, … access_log.processed.1, access_log.processed.

  4. If any of directories with names in 'YYYY-MM' format for the recalculation period are missing, create them by running the command:

    for y in <year_first> <year_last> ; do for m in `seq 1 12` ; do mkdir ${HTTPD_VHOSTS_D}/system/${vhost_name}/statistics/webstat/$y-$(printf "%.2d" $m) ; done ; done

    <year_first> and <year_last> are the first and the last years of the period for which you want to recalculate statistics.

  5. Run the following cycle to build statistics pages:

    for y in <year_first> <year_last> ; do \

    for m in `seq 1 12` ; do \

    dest_dir=$HTTPD_VHOSTS_D/system/$vhost_name/statistics/webstat/$y-$(printf "%.2d" $m) ; \

    $awstats $awstats_gen_opts -month=$m -year=$y -output > $dest_dir/awstats.${vhost_name}-http.html ; \

    ln -s $dest_dir/awstats.${vhost_name}-http.html $dest_dir/index.html ; \

    for output in alldomains allhosts lasthosts unknownip allrobots lastrobots session urldetail urlentry urlexit osdetail unknownos refererse refererpages keyphrases keywords errors404 ; do \

    $awstats $awstats_gen_opts -month=$m -year=$y -output=$output > $dest_dir/awstats.${vhost_name}-http.$output.html ; \

    done ; \

    done ; \


  6. Run statistics to update the upper frame navigation menu with a month listing:

    $PRODUCT_ROOT_D/admin/sbin/statistics --calculate-one --domain-name=$vhost_name


Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.