Intro

With current hot topic of ditching Google services wherever and whenever we can, we often forget about that little piece of JavaScript code embedded in most of modern internet websites. The short little code snippet is basis for Google Analytics and it helps us understand what is hot and what not on our site, so we can better adjust our content.

As always, data is valuable, and we should try to avoid giving it up to Google for free when possible.

So today, we will tackle that issue with the use of GoAccess.

GoAccess

The good people of internet have provided us with this wonderful piece of code called GoAccess. Despite the “Go” in the name, suggesting that we are dealing with currently hot GO code, it is in fact written in C and it is blazing fast.

To summarize directly from the official website:

GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea is to quickly analyze and view web server statistics in real time without needing to use your browser (great if you want to do a quick analysis of your access log via SSH, or if you simply love working in the terminal).

While the terminal output is the default output, it has the capability to generate a complete, self-contained real-time HTML report (great for analytics, monitoring and data visualization), as well as a JSON, and CSV report.

Temporary stats

Most basic usage of GoAccess is reviewing the stats directly in the terminal:

goaccess /var/log/nginx/sslvhost-b4d.sablun.org-access.log -c

If terminal does not satisfy your needs, you can export the stats to html and view them with browser in real-time. Even if you only run this mode for a few minutes at most, make sure you lock down the site for your eyes only (password protected, IP whitelisting, localhost only,…).

goaccess /var/log/nginx/sslvhost-b4d.sablun.org-access.log -o /var/www/sablun.org/report.html --log-format=COMBINED --real-time-html

Permanent stats

When you want to brag about your site traffic, set up automatic stats generation. As you are permanently opening this site to public, make sure to protect it, otherwise you are still leaking data.

You should probably fine tune your logrotate setting, to set up the date period for the stats display.

Use a cron job to generate the statistics:

vim /etc/cron.d/goaccess-stats

# Create statistics page for nginx with goaccess */15 * * * * root goaccess /var/log/nginx/sslvhost-b4d.sablun.org-access.log -o /var/www/sablun.org/report-b4d-sablun-org.html --log-format=COMBINED >/dev/null 2>&1

See Also