Parsing nginx logs with GoAccess and creating a HTML report in a cron job
source link: https://alexanderzeitler.com/articles/parsing-nginx-logs-with-goaccess-and-creating-a-html-report-using-a-cron-job/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Parsing nginx logs with GoAccess and creating a HTML report in a cron job
Photo by Luke Chesser on Unsplash
Gyula recently asked for a decent cookieless analytics tool on Twitter:
I suggested to use GoAccess to parse the nginx logs and create a HTML report and Hannes asked for a quickstart - so here we go.
Considering we're a running a Linux server with nginx and Docker, here's how to get started and our blog is static HTML generated with 11ty it is as easy as this to have a cron job running every day at 22:05 to create a HTML report of the nginx logs:
5 22 * * * cat /var/opt/deploy/logs/nginx/access.log | /usr/bin/docker run --rm -i -e LANG=$LANG allinurl/goaccess -a -o html --log-format COMBINED - > /var/opt/deploy/www/_site/report.html
The command in detail:
5 22 * * *
- run the command every day at 22:05
cat /var/opt/deploy/logs/nginx/access.log
- read the nginx access log
|
- pipe the output to the next command
/usr/bin/docker run --rm -i -e LANG=$LANG allinurl/goaccess -a -o html --log-format COMBINED -
- run the docker container with the GoAccess image and parse the nginx access log and create a HTML report
> /var/opt/deploy/www/_site/report.html
- write the HTML report to the file system
The report:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK