/*
 * Accueil; tout; à propos + @ + FAQ;
 * => Lire cette page via gemini (gemini?);
 */

How to setup goaccess to get nice stats with OpenBSD httpd

Since I have the pleasure to host the OpenBSD Webzine, the main author (Solène, that's you ;)) asked for some data about number of visits.

First, I dont want matomo : MariaDB, PHP, user tracking... Hum, not for me.

Then, I thought about webalizer, a log analyzer to generate charts. I like it, but as Solène notices, charts are image and not so easy to read.

Finally, I gave goaccess a new try and set it to generate html reports periodically for the webzine and my own website.

This is how I set up webalizer for multiple domains.

httpd setup

I like my logs to combined format. In server configuration "/etc/httpd.conf" :

server "athome.tld" {
    root "/htdocs/athome.tld"
    log style combined
    log access "athome.tld.log"
    ...

As you can see, logs are stored in "/var/www/logs/athome.tld.log"

Goaccess setup

First, let's install goaccess. Easy

# pkg_add goaccess

Then, edit "/etc/goaccess/goaccess.conf" for global configuration.

# httpd logs combined
date-format %d/%b/%Y
time-format %T %z
log-format %v %h %^ %^ [%d:%t] "%r" %s %b "%R" "%u"
# keep visitors identity safe
anonymize-ip true
# keep old stats
persist true
restore true

Other options will be set at command line.

Stats

I find more convenient to use a script for each server and store goaccess history in a dedicated directory. We will assume the server files belongs to user "foo".

# mkdir -p /var/db/goaccess/athome.tld
# chown foo /var/db/goaccess/athome.tld

Now, create a script to call goaccess with approriation flags.

#!/bin/sh
# generate goaccess stats
out=/var/www/htdocs/athome.tld/stats.html
db=/var/db/goaccess/athome.tld
log=/var/www/logs/athome.tld.log
title="My website stats"
u=foo
/usr/local/bin/goaccess $log \
  -o $out \
  --db-path=$db \
  --user-name=$u \
  --html-report-title="$title"

Notice the use of "--user-name".

Automatic updates

Set up a crontab to start above script

6,10,19,21 * * * * /usr/local/bin/goaccess-athome.tld.sh > /dev/null 2>&1

Here, stats are generated at 6am, 10am, 7pm and 9pm. You might use "@hourly" as well.

Report generation before log rotate

Edit /etc/newsyslog.conf to call goacces before logs archiving :

/var/www/logs/athome.tld.log               644  7     250  $W0   Z  "/usr/local/bin/goaccess-athome.tld.sh && pkill -USR1 -u root -U root -x httpd"

Real time

Yeah, goaccess can listen to a port for automatic updates (with real-time and daemonize flags). It requires to load ssl certificates, but those keys belongs to root only on OpenBSD. You can copy and change permissions on them, or start goaccess realtime as root. I think it's a bad idea to start a process as root.

Links

OpenBSD Webzine
Solène
webalizer
goaccess

Something to say ?

Send your comment by mail.