Monitor OpenBSD Website Activity With GoAccess

WIP!

Most of this site is incomplete, and the current state is available as an open draft. Most of the text here is likely incomplete, misinformed, or just plain wrong. I'm looking for feedback on my website, so that I can:

To anyone who wants to send me feedback, thank you, and shoot me an email!

By default, Httpd sites log out requests to OpenBSD’s standard access and error files, generally located in /var/log/access.log and /var/log/error.log. GoAccess, a third-party log analyzer, is designed to view web server stats through a terminal, so you can quickly check them over SSH or if you simply love the terminal.

A colored curses screen depicting a website's overall statistics, daily unique visitors, and the top requested files.
Terminal view of GoAccess 1.5.5

Configure Httpd Sites

To use GoAccess effectively, I’ve set up my sites to write access logs to site-wide files, and changed the log style to provide more information:

server "example.org" {
    

    log access "example.org.log"

    # The "combined" log style adds to the default "common" log style by providing
    # the user's referrer (the URL which linked to your site) and user agent.
    log style combined
}

Tell Httpd to use the latest config files:

$ doas rcctl reload httpd

Install and Configure GoAccess

GoAccess is third-party, so it needs to be installed on-top of the base system:

$ doas pkg_add goaccess

By default, GoAccess will give you a menu list of log formats to use whenever launching the program. It provides a list of presets, such as Common logging and Combined logging, but these presets assume Apache’s or Nginx’s interpretation. GoAccess’s config file /etc/goaccess/goaccess.conf has a commented-out block of settings suggested for httpd(8):

# httpd(8) combined log format
#date-format %d/%b/%Y
#time-format %T %z
#log-format %v %h %^ %^ [%d:%t] "%r" %s %b "%R" "%u"

Commenting out these three lines removes the log format dialog and correctly interprets our logs.

Using GoAccess on the Terminal

The simplest way to use GoAccess is to run the command on a log file:

$ goaccess /var/www/logs/example.org.log

It provides a few panels that give an overall idea of your website’s traffic and audience:

Generating (and automating) a report

GoAccess can generate self-contained HTML, CSV, and HTML reports:

$ goaccess /var/www/logs/example.org.log -o ~/report.html
A dark-themed HTML document depicting a website's overall statistics, a line chart visualizing unique daily visitors, and a bar graph visualizing most requested files.
GoAccess 1.5.5 HTML report

I like the way the HTML report looks, and the graphics give more insight than I feel the terminal could provide. Because the entire webpage is self-contained, I made a script to automate a generated weekly report to send to my mail. This requires a mail server already set up, and the report script itself can run locally.

Assuming I set up the local email account webmaster, I can spin up a cron job on a local user to run the command weekly:

@weekly          $HOME/bin/sendreport webmaster example.org

External Links