[imp] analyse horde logs - RRD-Tool

Oliver Kuhl okuhl at netcologne.de
Mon Apr 28 15:13:46 PDT 2003


Hi!

> is there any software in order to easily analyse the Horde's logs ?
I don't know. But if you want to see stats, I created a neat rrd-tool graphic which shows the different apps that are used. I greps a bit out of apache's access.log.

Just look at the image, to get an idea. ;-)

I attached my scripts. The create*-script creates the rrdatabase. Updatedata updates the data in the db. This one has to be called by cron. Updategraph creates the images. I use it with a php-script that only updates the graphics, if there is never data in the db. This looks like the following:

<?php
$module = "apachehits";

$lastupdate_timestamp      = filectime("../data/".$module.".rrd");
$lastupdategraph_timestamp = filectime("../images/".$module."-week.gif");
$lastupdate                = date("d.m.Y H:i:s", $lastupdate_timestamp);
$lastupdategraph           = date("d.m.Y H:i:s", $lastupdategraph_timestamp);

//echo("rrd: $lastupdate_timestamp(".date("d.m.Y H:i:s", $lastupdate_timestamp).")<br>");  
//echo("graph: $lastupdategraph_timestamp(".date("d.m.Y H:i:s", $lastupdategraph_timestamp).")<br>");

if($lastupdate_timestamp > $lastupdategraph_timestamp) {
    echo("Erstelle Grafiken...<br>");
    flush();
    exec("../scripts/".$module."_updategraph.sh day");
    ?><IMG src="../images/<?php echo($module); ?>-day.gif" alt="Daily Stats" border=0><br><?php
    flush();
    exec("../scripts/".$module."_updategraph.sh week");
    ?><IMG src="../images/<?php echo($module); ?>-week.gif" alt="Weekly Stats" border=0><br><?php
    flush();
    exec("../scripts/".$module."_updategraph.sh month");
    ?><IMG src="../images/<?php echo($module); ?>-month.gif" alt="Monthly Stats" border=0><br><?php
    flush();
    exec("../scripts/".$module."_updategraph.sh year");
    ?><IMG src="../images/<?php echo($module); ?>-year.gif" alt="Yearly Stats" border=0><br><?php
    echo("fertig.<br>");
} else {
   ?>
   <IMG src="../images/<?php echo($module); ?>-day.gif" alt="Daily Stats" border=0><br>
   <IMG src="../images/<?php echo($module); ?>-week.gif" alt="Weekly Stats" border=0><br>
   <IMG src="../images/<?php echo($module); ?>-month.gif" alt="Monthly Stats" border=0><br>
   <IMG src="../images/<?php echo($module); ?>-year.gif" alt="Yearly Stats" border=0><br>
   <?php
}
?>

Take care of the rights. The updategraph-script must be executable for your webserver as well as the webserver must be able to read the db and of course be able to write the images.

Enjoy.

Gruss,
   Ollie.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: apachehits-day.gif
Type: image/gif
Size: 68479 bytes
Desc: not available
Url : http://lists.horde.org/archives/imp/attachments/20030428/d56c7ee1/apachehits-day-0001.gif
-------------- next part --------------
#!/bin/sh

mod=apachehits

basedir=/var/www/rrd
dbdir=$basedir/data
db=$dbdir/$mod.rrd
logfile=/var/log/apache-ssl/access.log

PATH=/bin:/usr/bin:/usr/local/bin
LINES=1000

HITS=`wc -l $logfile | awk '{print $1}'`
IMP=`tail -$LINES $logfile | grep imp | wc -l | awk '{print $1}'`
TURBA=`tail -$LINES $logfile | grep turba | wc -l | awk '{print $1}'`
KRONOLITH=`tail -$LINES $logfile | grep kronolith | wc -l | awk '{print $1}'`
GOLLEM=`tail -$LINES $logfile | grep gollem | wc -l | awk '{print $1}'`
INGO=`tail -$LINES $logfile | grep ingo | wc -l | awk '{print $1}'`
FORWARDS=`tail -$LINES $logfile | grep forwards | wc -l | awk '{print $1}'`

#echo HITS:$HITS IMP:$IMP TURBA:$TURBA KRONOLITH:$KRONOLITH GOLLEM:$GOLLEM INGO:$INGO FORWARDS:$FORWARDS
/usr/bin/rrdtool update $db N:$HITS:$IMP:$TURBA:$KRONOLITH:$GOLLEM:$INGO:$FORWARDS
-------------- next part --------------
#!/bin/sh

mod=apachehits

#
# Verzeichnis- und Dateiangaben
#
basedir=/var/www/rrd
graphdir=$basedir/images
graph=$graphdir/$mod-$1.gif

dbdir=$basedir/data
db=$dbdir/$mod.rrd

#
# aktuelle Zeit
#
time=`/bin/date | /usr/bin/cut -d" " -f-4`

if [ $1 ]
then
    echo 'updategraph.sh 0.1 by Oliver Kuhl'
    
    case $1 in
        day) start='-86400'
             descr='Apache Hits (last 24 hours)';;
    
        week) start='-604800'
              descr='Apache Hits (last week)';;

        month) start='-2592000'
               descr='Apache Hits (last month)';;

        year) start='-31536000'
              descr='Apache Hits (last year)';;
    esac


    rrdtool graph $graph \
            --start $start \
            --height 200 \
            --width 600 \
            --title="$descr" \
            --vertical-label="Hits" \
            --lower-limit 0 \
            DEF:all="$db":apachehits:AVERAGE \
            DEF:imp="$db":apachehitsimp:AVERAGE \
            DEF:turba="$db":apachehitsturba:AVERAGE \
            DEF:kronolith="$db":apachehitskronolith:AVERAGE \
            DEF:gollem="$db":apachehitsgollem:AVERAGE \
            DEF:ingo="$db":apachehitsingo:AVERAGE \
            DEF:forwards="$db":apachehitsforwards:AVERAGE \
            CDEF:cdefall=all,300,* \
            CDEF:cdefimp=imp,all,300,*,*,1000,/ \
            CDEF:cdefturba=turba,all,300,*,*,1000,/ \
            CDEF:cdefkronolith=kronolith,all,300,*,*,1000,/ \
            CDEF:cdefgollem=gollem,all,300,*,*,1000,/ \
            CDEF:cdefingo=ingo,all,300,*,*,1000,/ \
            CDEF:cdefforwards=forwards,all,300,*,*,1000,/ \
            CDEF:rest=1000,imp,turba,kronolith,gollem,ingo,forwards,+,+,+,+,+,- \
            CDEF:cdefrest=rest,all,300,*,*,1000,/ \
            AREA:cdefimp#FF0000:"Webmail       (IMP)             " \
            GPRINT:cdefimp:LAST:"Current\:%8.0lf" \
            GPRINT:cdefimp:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefimp:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefturba#EA8F00:"Adressbuch    (Turba)           " \
            GPRINT:cdefturba:LAST:"Current\:%8.0lf" \
            GPRINT:cdefturba:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefturba:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefkronolith#FFF200:"Kalender      (Kronolith)       " \
            GPRINT:cdefkronolith:LAST:"Current\:%8.0lf" \
            GPRINT:cdefkronolith:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefkronolith:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefgollem#00FFFF:"Dateimanager  (Gollem)          " \
            GPRINT:cdefgollem:LAST:"Current\:%8.0lf" \
            GPRINT:cdefgollem:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefgollem:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefingo#0000FF:"Filter        (Ingo)            " \
            GPRINT:cdefingo:LAST:"Current\:%8.0lf" \
            GPRINT:cdefingo:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefingo:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefforwards#8D00BA:"Weiterleitung (Forwards)        " \
            GPRINT:cdefforwards:LAST:"Current\:%8.0lf" \
            GPRINT:cdefforwards:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefforwards:MAX:"Maximum\:%8.0lf\n" \
            STACK:cdefrest#555555:"Sonstiges                       " \
            GPRINT:cdefrest:LAST:"Current\:%8.0lf" \
            GPRINT:cdefrest:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefrest:MAX:"Maximum\:%8.0lf\n" \
            COMMENT:"------------------------------------------------------------------------------------------" \
            COMMENT:"\n" \
            LINE1:cdefall#000000:"Web Hits overall                " \
            GPRINT:cdefall:LAST:"Current\:%8.0lf" \
            GPRINT:cdefall:AVERAGE:"Average\:%8.0lf" \
            GPRINT:cdefall:MAX:"Maximum\:%8.0lf\n" \
            COMMENT:"\n" \
            COMMENT:"last update: $time"

else
    echo "Syntax: ${mod}_updategraph.sh {day|week|month|year}"
fi
-------------- next part --------------
#!/bin/sh
mod=apachehits

basedir=/var/www/rrd
dbdir=$basedir/data
db=$dbdir/$mod.rrd

rrdtool create $db \
--step 300 \
DS:apachehits:COUNTER:600:0:999999 \
DS:apachehitsimp:GAUGE:600:0:999999 \
DS:apachehitsturba:GAUGE:600:0:999999 \
DS:apachehitskronolith:GAUGE:600:0:999999 \
DS:apachehitsgollem:GAUGE:600:0:999999 \
DS:apachehitsingo:GAUGE:600:0:999999 \
DS:apachehitsforwards:GAUGE:600:0:999999 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 


More information about the imp mailing list