Site icon David Yin's Blog

Use GoAccess 1.5.5 to Generate Report with Multiple Nginx Log Files

I have a post about How to use GoAccess two years ago. It is kind of outdated. Now it is a new version for telling you how to make a report in the current world.

I have a VPS with Nginx as a web server and also a lot of websites on it. It is on Digital Ocean.

Here is the VPS basic information.

All sites use one access.log file. The following code is in the http block of /etc/nginx/nginx.conf file.

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

All access logs look like below:

Now it is time to show you how to use GoAccess to Generate Reports with Multiple Nginx Log files.

Install GoAccess

The GoAccess in the Ubuntu repo is too old. Version 1.3, released about 2016. So I decided to use the goaccess’s own repository as below to install the latest version 1.5.5.

$ wget -O - https://deb.goaccess.io/gnugpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/goaccess.gpg >/dev/null
$ echo "deb [signed-by=/usr/share/keyrings/goaccess.gpg] https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/goaccess.list
$ sudo apt-get update
$ sudo apt-get install goaccess

 

Modify the Config file of GoAccess

GoAccess config file is located at /etc/goaccess/

sudo nano /etc/goaccess/goaccess.conf

Add the following code or modify the code inside of the goaccess.conf file.

time-format %H:%M:%S

date-format %d/%b/%Y

log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"

geoip-database /var/GeoIP/dbip-city-lite-2022-02.mmdb

db-path /var/goaccess/cache

persist true

restore true

I downloaded the mmdb format GeoIP2 IP database from https://db-ip.com/db/download/ip-to-city-lite
Decompress it and put it at /var/GeoIP/

Then I made a folder at /var/goaccess/cache

Run GoAccess to generate the report

I would like to get a static report.

sudo goaccess /var/log/nginx/access.log -o /home/davidyin/mywebsite.com/report.html --log-format=COMBINED

The report looks like below:

Due to the log is not just one file. The log files are generated by date and also compressed.

Two log files are not compressed.

The older log files are compressed.

I want to generate all the access log files. So the command is changed to the way which can phrase multiple log files.

sudo zcat /var/log/nginx/access.log.*.gz | sudo goaccess /var/log/nginx/access.log /var/log/nginx/access.log.1 - -o /home/davidyin/mywebsite.com/report.html --log-format=COMBINED

The sample command above uses mywebsite.com. Please replace it with your own sites.

At the last, I add the command below into Cron jobs. Schedule it every hour.

sudo goaccess /var/log/nginx/access.log -o /home/davidyin/mywebsite.com/report.html --log-format=COMBINED
Exit mobile version