HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Installation/Configuration (http://www.howtoforge.com/forums/forumdisplay.php?f=27)
-   -   AWStats does not calculate last day (http://www.howtoforge.com/forums/showthread.php?t=53475)

erosbk 20th July 2011 13:51

AWStats does not calculate last day
 
AWStats statistics program does not calculate last day of month. As I could see, every day 1 of all months, in stats I can only see the current month, instead of previous month with traffic of the last day.

Is this normal for AWstats in ispconfig? or is just a bug in my installation?

erosbk 20th July 2011 15:55

As I could see, reinstalling everything in a VM, ISPConfig is not calculating last day of previous month, directly calculating the new month showing all values in zero...

I will follow in this post what I wrote here:
http://www.howtoforge.com/forums/showthread.php?t=53282

I added this code to cron_daily, in a VM using log files and previous stats from a production server but... when I calculate last day for a previous month, all previous data is removed...

I will test this in 10 days in my production server to see if it works as it should... but I think that I will have the same results... so, please help, I think that this could be great for clients to see preivous month statistics and compare between months.

--- with this script right now, every first day of month, stats will be calculated twice, one for current month, one for previous month (to complete last day). This can be modified to always calculate one time only, and day 2 copy files to "previous month folder" BEFORE running stats calculation... ---

Code:

#######################################################################################################
// Create awstats statistics
#######################################################################################################

$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);

$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');

foreach($records as $rec) {
        //$yesterday = date('Ymd',time() - 86400);
        $yesterday = date('Ymd',strtotime("-1 day", time()));
        $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log');
        if(!@is_file($logfile)) {
                $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log.gz');
                if(!@is_file($logfile)) {
                        continue;
                }
        }

        $domain = escapeshellcmd($rec['domain']);
        $statsdir = escapeshellcmd($rec['document_root'].'/web/stats');
// BOC 1: Copy previous month statistics to dir /[year][month]/*
        if (date("d") == 1)
        {
                $statsprev = '/'.date("Y").(date("m")-1);
                if (date("m") == 1)
                {
                        $statsprev = '/'.(date("Y")-1).'12';
                }
        }
        $statsdirold = $statsdir.$statsprev."/";
        mkdir($statsdirold);
        $files = scandir($statsdir);
        foreach ($files as $file)
        {
              if (substr($file,0,1) != "." && substr($file,0,1) != "2" ) copy("$statsdir"."/"."$file", "$statsdirold"."$file");
        }
// EOC 1:


        $awstats_pl = $web_config['awstats_pl'];
        $awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
        $awstats_conf_dir = $web_config['awstats_conf_dir'];
        $awstats_website_conf_file = $web_config['awstats_conf_dir'].'/awstats.'.$domain.'.conf';
       
        if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file);
       
        if(!is_file($awstats_website_conf_file)) {
                $awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf"
LogFile="/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log"
SiteDomain="'.$domain.'"
HostAliases="www.'.$domain.' localhost 127.0.0.1"';
                file_put_contents($awstats_website_conf_file,$awstats_conf_file_content);
        }
       
        if(!@is_dir($statsdir)) mkdir($statsdir);
        if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
        symlink($logfile,'/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
       
        // awstats_buildstaticpages.pl -update -config=mydomain.com -lang=en -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
        $command = "$awstats_buildstaticpages_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";
       
        if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
                exec($command);
                rename($rec['document_root'].'/web/stats/awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/index.html');
                $app->log('Created awstats statistics with command: '.$command,LOGLEVEL_DEBUG);

// BOC 2: Calculate last day for previous month. -month and -year must be variables, right now are fixed values for testing purpose
                if (date("d") == 1)
                {
                        $command = "$awstats_buildstaticpages_pl -month=06 -year=2011 -update -config='$domain' -lang=en -dir='$statsdirold' -awstatsprog='$awstats_pl'";
                        exec($command);
                        rename($rec['document_root'].'/web/stats'.$statsprev.'/'.'awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/'.$statsprev.'/'.'index.html');
                }
// EOC 2:

// BOC 3: Add code here to create a index.html with dropdown list to select year/month to view, and point selection to directory. This can be done for ispconfig when AWStats are selected as web stats type, and create one time as static index.html, creating drop down reading directories dinamically...
// EOC 3:

        } else {
                $app->log("No awstats statistics created. Either $awstats_pl or $awstats_buildstaticpages_pl is not owned by root user.",LOGLEVEL_WARN);
        }
       
}


critorix 19th January 2012 19:34

Hi,

Did you succeed in showing more than one month in awstats ?

I have the same problem.

Thanks in advance.
critorix

till 19th January 2012 19:38

This has been fixed long ago.You should update ispconfig on your server to the recent version (3.0.4.2).

critorix 19th January 2012 19:47

Ok, thank you.

I have the 3.0.3.3, is it possible to re-generate the previous months stats after the upgrade ?

erosbk 19th January 2012 20:09

Quote:

Originally Posted by critorix (Post 271939)
Ok, thank you.

I have the 3.0.3.3, is it possible to re-generate the previous months stats after the upgrade ?

If you have a backup of previous stats, after upgrade it is possible. But if you don't have a backup of previous stats I don't know how much you can go back to previous logs to regenerate stats from them..

critorix 19th January 2012 22:55

Thank you.

I upgraded to the latest version and will try to regenerate stats.


All times are GMT +2. The time now is 00:21.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.