GoAccess – Analyze Real-Time Apache and Nginx Logs

One of the primary roles of any systems administrator is viewing and analyzing log files. Web server log files from other Apache and Nginx can build up over time and examining them can prove to be a tedious and time-consuming activity. Thankfully, GoAccess can alleviate all that stress and enable you to seamlessly monitor and analyze web server log files.

Written in C programming language, GoAccess is an opensource, terminal-based real-time web log analyzer. It’s fast, interactive, and displays the logs in an elegant and intuitive fashion. It provides support for a wide variety of web log files including Apache, Nginx, Caddy, Amazon S3, and CloudFront to mention just a few. It can render the results in HTML format, JSON, and also generate a CSV report.

In this guide, we will focus on how to install goaccess and use it to analyze real-time Apache and Nginx web server logs.

GoAccess allows you to view the following log metrics:

  • Daily unique visitors
  • Requested files
  • Static requests ( jpg, pdf, png, mp4, avi, etc)
  • Not found (404) requests
  • Visitors’ hostname and IP details
  • Visitor’s Operating system & browser details
  • Geo Location

How to install GoAccess

There are two main ways of installing GoAccess on your Linux system. You can either build from source or use your distribution’s package manager. Let’s check out how you can accomplish doing both.

Install GoAccess on various distributions

Here’s how you can install GoAccess on various Linux distributions.

On Ubuntu / Debian distributions

If you are running Ubuntu or any Debian-based system, execute:

$ sudo apt install -y goaccess

On RHEL / CentOS

For RHEL and CentOS-distros, run the command:

$ sudo yum install -y goaccess
or$ sudo dnf install -y goaccess

On Fedora

On Fedora, run the command:

$ sudo dnf install goaccess -y

On Arch Linux

For Arch Linux and other Arch-distros such as Arch Linux and Manjaro, run the command.

$ sudo pacman -S goaccess

For other distributions such as OpenSUSE and UNIX flavors such as FreeBSD, visit the official GoAccess download link.

Install GoAccess from source

To install from source, first, download the GoAccess tarball file using wget command

$ wget https://tar.goaccess.io/goaccess-1.4.6.tar.gz

Extract the tarball file with beneath tar command

$ tar -xvf goaccess-1.4.6.tar.gz

Then, navigate into the directory and build from source as shown.

$ cd goaccess-1.4.6/
$ ./configure --enable-utf8 --enable-geoip=mmdb
$ make
# make install

Verify the installation

To confirm that GoAccess has been installed, run the following command.

$ goaccess

This will print or display the command usage and command options as shown.

goacces-command-output-linux

In addition, you can check the version of GoAccess as shown.

$ goaccess --version

goaccess-version-check-linux

How to use GoAccess to Monitor Ream-Time Apache & Nginx logs

Once you have installed GoAccess, The next step is to monitor the web log files. In this example, we have the Apache web server installed and we are going to monitor the access.log file to view statistics on how clients are interacting with the web server from a browser.

The -f option allows you to view real-time the logs on the command line

$ goaccess -f /var/log/apache2/access.log --log-format=COMBINED

Goaccess-Apache2-logs-Combined

Your web server’s log statistics will be printed on the terminal including total requests, valid requests, valid visitors, unique files and so many more.

Apache2-Logs-Audit-Linux-Terminal

Be sure to scroll down to view other web server statistics such as Not Found 404 requests, visitor hostnames, and IP addresses.

Apache2-Access-logs-Linux

Here, we have statistics on the operating systems and web browsers from which the visitors are accessing the web server.

Apache2-WebServer-Statistics-Logs-Linux

To monitor Nginx logs, use the same drill as you did when monitoring Apache logs. Just switch to root user and run the command below.

# goaccess -f /var/log/nginx/access.log --log-format=COMBINED

Goaccess-nginx-access-log-combined-linux

Here, we are monitoring the access.log  file for the Nginx web server

Nginx-WebServer-Realtime-Logs

Visibly, the dashboard is strikingly similar to what we had when monitoring Apache logs

View logs output on a web dashboard

You can also render the web server logs on elegant and intuitive dashboards by redirecting the output in an html file as shown. Here’s we have specified the output file as reports.html.

$ goaccess -f /var/log/apache2/access.log --log-format=COMBINED > reports.html

Next, open your web browser and browse the location of the file which will immediately render the logs in beautiful dashboards as shown.

Goaccess-webserver-reports-broswer

Summary

GoAccess is a useful tool that gives you tons of insights about your web server’s interaction with visitors on your website. It allows you to obtain a wealth of detailed information about visitors’ interaction with your site that can prove useful in reaching a wider audience and improving user experience.

Leave a Reply

Your email address will not be published. Required fields are marked *