How to: GoAccess to generate HTML reports

GoAccess is a very powerful Apache/Nginx log analyser.

It gives very important information in a digestible form.

Installation

Installation is very easy on both CentOS and Ubuntu:

For Ubuntu

sudo apt-get install goaccess

For CentOS

sudo yum install goaccess

Yes, Thats it.

… Okay not really there is a tiny bit of configuration that is needed

Configuration

For Both OS’s

sudo nano /etc/goaccess.conf

Uncomment a Date format, Time format and Log format.

Now you’re ready to start using GoAccess

Usage

I will only be showing how to generate html reports using GoAccess rather than the live view in terminal

Depending on your configuration for your virtual hosts you may have logs enabled in different locations, if you have configured this, you’ll probably know how to change the path int he next command.

To generate your first html report please use this command:

For Both OS’s

goaccess -f /var/log/apache2/access.log -a > report.html

This will output a file “report.html” in whichever directory you are currently in. That’s how simple it is to make a report with GoAccess.

Automation and Authentication

When considering automation I tend to go with the simplest approach, Lets say a nice simple crontab (If you do not know how to create a crontab this will be in a future guide).

Using crontabs it would be quite simple to have a directory which logs are outputted to and amended with the current date and time for the report on the webserver to view at your leisure. However this would also leave the logs to the general public to stumble across.

To combat this you could output the logs into a folder which requires basic http auth using a .htaccess file. However, if you have a little PHP knowledge and know how to make a simple login system I prefer to rename the report to .php and echo something simple like the example below into the top of the file to require logging in to view the reports:


<?php
session_start();
if (!isset($_SESSION['username'])) {
  header('Location: /login.php');
  exit;
} 
?>

More Appropriate/Advanced usage

The above report is statistics for all hosted sites. It would be better to have individual reports for each site. All you need to do for this is set a custom log location in the virtual host for each site, now when creating the report you can create them for individual sites as you can process each sites log separately.

You May Also Like

About the Author: trader418

Leave a Reply

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