go41

Awstats Statistik Plesk – Daten letzter Monat

Awstats Statistik Plesk – Daten letzter Monat

von Joern am 1. Jan. 2008 | Keine Kommentare

Problem: AWSTATS unter Plesk zeigt nur den aktuellen Monat, am ersten Tag des Monats sind die Statistiken der vorigen Monate nicht mehr da.Die alten Statitstiken liegen dann als Textfile unter: ($vhostDir/$webstatDir/awstats*.$vhostBaseName-http.txt)

Wie kann man die jetzt wieder im Browser sichtbar machen?

Auf dem Forum von SWsoft (Link am Ende des Beitrags) habe ich eine Lösung gefunden, die bei mir funktioniert.

Es gibt da einen Script, der die alten Daten in html Dateien umwandelt, ein Frameset erstellt und es möglich macht, alle gefundenen alten Statistiken von AWstats auf einem Plesk Server mit dem Browser zugänglich zu machen.

Ich habe die Variablen des Scripts meinem vServer bei Webperoni anpassen müssen, da je nach Betriebssystem und Plesk Version die Verzeichnisse wohl unterschiedlich sind.

Der Script so wie er bei mir läuft sieht so aus: (keine Garantie dass der Code richtig kopiert werden kann!! Besser von der Originalseite holen!!)

CODE:

#!/bin/sh
## The following script is meant to allow the viewing of last months awstats
## information on Plesk servers. It creates the statistics for all found
## awstats monthly data and a frameset to allow to choose a month from the
## generated ones.
##
## The main idea behind this file is to avoid any changes to the installed Plesk.
## So I’m misusing e.g. the at_domains_index.html which is first in Apaches
## DirectoryIndex configuration on Plesk servers to display the frameset, e.g.
##
## It was written on a Debian 3.1 (Sarge) and will probably not work on other
## distributions because of different paths, scripts, etc.
##
## BEWARE: This works on my box, but it might crash your system, delete all
## existing files on it and make you loose your job. So
## USE AT YOUR OWN RISK. I’M NOT RESPONSIBLE FOR ANY DAMAGE THIS
## SCRIPT DOES ON YOUR SERVERS. USE IT WITH CARE AND MAKE SURE YOU
## UNDERSTAND WHAT YOU ARE DOING.
##
## The script is fairly new and should be called „alpha“ in this state,
## but it seems to works fine here.
##
## Notes:
## – The script only loops through all virtual hosts in /var/www/vhosts/
## and does not check wether awstats is enabled for the host in Plesk
## (it is for all domains on the machine this script was written for)
## – It does not update the awstats data from logfiles, but uses the
## ones that were created by awstats in the daily runs
## – it is probably best used by putting it into /etc/cron.monthly/
## (don’t forget to make it executable
## – it is to be run as root, so have a look at the BEWARE above
##
## 2007-04-17 – initial release
## by Thomas „Balu“ Walter <walter@bartels-schoene.de>
##
## 2007-04-19 – customized for Plesk 8.1 on RHEL/CentOS 4 and some fixes
## by Toneworks Studios <jeroen@toneworks.nl>

# set some variables
buildStaticPages=“/usr/share/doc/packages/awstats/tools/awstats_buildstaticpages.pl“
webstatDir=’statistics/webstat‘
webstatRoot=’plesk-stat/webstat‘
awstats_configdir=’/usr/local/psa/etc/awstats‘
awstats_prog=’/srv/www/cgi-bin/awstats.pl‘
vhostsdir=’/srv/www/vhosts‘ # no tailing slash
forceupdate=0
useFullUrls=0

# if you want to translate the title of the frameset or the text in front
# of the select box, update the following variables which are only used for the
# first creation of the files
tlStatsFor=“Statistics for“
tlShowStatsFor=“Show statistics for:“
tlThisMonth=“this month“

# awstats on debian needs this to override configdir
export AWSTATS_ENABLE_CONFIG_DIR=1

# to avoid generating of this months stats which is done by cron.daily
thisMonth=`date +%m`
thisYear=`date +%Y`

# loop through all virtual hosts
# TODO it would probably be better to fetch the awstats enabled hosts directly
# from the database, but what the heck
for vhostDir in `find $vhostsdir -maxdepth 1 -type d`
do
# get only the virtual hosts name
vhostBaseName=`basename $vhostDir`
#echo „#### domain „$vhostBaseName““

# don’t create statistics for those
if [[ „$vhostBaseName“ == „default“ ]]; then
continue
fi
if [[ „$vhostBaseName“ == „chroot“ ]]; then
continue
fi
if [[ „$vhostBaseName“ == „“ ]]; then
continue
fi

# skip if AWStats is not enabled for this domain
if [ ! -f „$vhostDir/$webstatDir/awstats.$vhostBaseName-http.html“ ]; then
continue
fi

fullWebstatRoot=““
if [ 1 == $useFullUrls ]; then
fullWebstatRoot=“http://$vhostBaseName/$webstatRoot/“;
fi

# create the frameset file
# I’m misusing at_domains_index.html here which is meant to be used for
# something else, but is first in Apaches DirectoryIndex setting in plesk
framesFile=“$vhostDir/$webstatDir/at_domains_index.html“
echo „<html><head><title>$tlStatsFor $vhostBaseName</title>“ > $framesFile
echo ‚</head><frameset rows=“27,*“ border=“0″ frameborder=“0″ framespacing=“0″>‘ >> $framesFile
echo ‚<frame src=“monthchooser.html“ name=“monthchooser“ scrolling=“no“ noresize=“noresize“ />‘ >> $framesFile
echo ‚<frame src=“index.html“ name=“statistics“ />‘ >> $framesFile
echo „</frameset></html>“ >> $framesFile

# create the month chooser frame
frameFile=“$vhostDir/$webstatDir/monthchooser.html“
echo ‚<html><head><title>Statistics</title></head><body>‘ > $frameFile
echo ‚<body style=“font: 12px verdana, arial, helvetica, sans-serif; background: #ececec;“ leftmargin=“2″ topmargin=“2″ marginwidth=“2″ marginheight=“2″>‘ >> $frameFile
echo ‚<form style=“margin: 0; padding: 0;“ action=“#“>‘ >> $frameFile
echo ‚<table border=0 cellspacing=0 cellpadding=0><tr><td valign=middle style=“font: 12px verdana, arial, helvetica, sans-serif;“>‘ >> $frameFile
echo $tlShowStatsFor >> $frameFile
echo ‚ </font></td><td valign=middle>‘ >> $frameFile
echo ‚ <select onChange=“parent.statistics.location.href = this.value;“>‘ >> $frameFile
echo ‚<option value=“‚$fullWebstatRoot’index.html“>'“$tlThisMonth“‚</option>‘ >> $frameFile
echo ‚<!– add next month here –>‘ >> $frameFile
echo ‚</select>‘ >> $frameFile
echo ‚</td></tr></table>‘ >> $frameFile
echo ‚</form></body></html>‘ >> $frameFile

## loop through all last months statistics stored by awstats
for monthFile in `ls $vhostDir/$webstatDir/awstats*.$vhostBaseName-http.txt 2>/dev/null`
do
monthFileBaseName=`basename $monthFile`

# figure out year and month from the filename (might be solved more elegant…)
month=`echo $monthFileBaseName | sed „s%awstats(..)(….).$vhostBaseName-http.txt%1%“`
year=`echo $monthFileBaseName | sed „s%awstats(..)(….).$vhostBaseName-http.txt%2%“`

if [[ $month == $thisMonth && $year == $thisYear ]]; then
continue
fi

# check if the stats for the month were already generated
if [[ 1 == $forceupdate || ! -e „$vhostDir/$webstatDir/$year-$month“ ]]; then

# if not create the stats directory
if [ ! -d „$vhostDir/$webstatDir/$year-$month“ ]; then
mkdir „$vhostDir/$webstatDir/$year-$month“
fi

# uncomment this if you want to see anything
#echo „Building for $vhostBaseName $year-$month“

# and build the statistics for the month
$buildStaticPages
-config=$vhostBaseName-http
-staticlinks
-configdir=$awstats_configdir
-month=$month
-year=$year
-awstatsprog=$awstats_prog
-dir=$vhostDir/$webstatDir/$year-$month >/dev/null 2>&1

# link index.html to the newly generated stats main page
ln -sf „$vhostDir/$webstatDir/$year-$month/awstats.$vhostBaseName-http.html“
„$vhostDir/$webstatDir/$year-$month/index.html“
fi

# add the statistics to the monthchooser
sed ’s%<!– add next month here –>%<!– add next month here –>'“n“‚<option value=“‚$fullWebstatRoot$year‘-‚$month’/index.html“>’$year‘-‚$month'</option>%‘
„$vhostDir/$webstatDir/monthchooser.html“ > „$vhostDir/$webstatDir/monthchooser.html.tmp“
mv „$vhostDir/$webstatDir/monthchooser.html.tmp“ „$vhostDir/$webstatDir/monthchooser.html“
done
done

CODE ENDE

diesen Script habe ich auf dem vServer unter :/etc/statsmonth abgelegt als awmonthly ohne eine Dateiendung.

Zum Starten des Script logge ich mich mit Putty ein:

root@lvpsxxyyzz.webperoni.de’s password:
Last login: Sat Dec 1 17:39:02 2007 from xyz.dip0.t-ipconnect.de
Have a lot of fun…

lvpsxxyyzz:~ # cd ..
lvpsxxyyzz:/ # cd etc
lvpsxxyyzz:/etc # cd statsmonth
lvpsxxyyzz:/etc/statsmonth # ./awmonth – das ist der eigentliche Startbefehl, jetzt muss man etwas warten, bis wieder der Prompt kommt!!
lvpsxxyyzz:/etc/statsmonth #

Wenn man nun seine AWstats Seite aufruft, hat man in der obersten Zeile ein Dropdown um die vorigen Monate auszuwählen, Spitze!

Awstats Plesk monthly

AWstats monthly on Plesk Server

Den Original Script und einige Kommentare hier: Plesk 8.1 for Linux Installation and ‚How Do I‘ Questions

Autor:

Du findest mich auch auf Google+, Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.