Official goaccess container with cron deamon running goaccess at intervals of your choice #2837
Replies: 2 comments
-
docker-compose, corresponding to the CLI above:
run with |
Beta Was this translation helpful? Give feedback.
-
Auto downloading geo database mmdb file.Now that cron is there, why not automate the mmdb geo database download inside the container? The attached shell script will download the latest mmdb file from The shell script is here (download and rename to Short breakdown:
Note. If you are running the container on ARM64, you need to switch the BINARY_URL variable in the script. Now, you can add a weekly download of the mmdb (if there is an update) by mounting the script and adding it to the crontab-file. Crontab-file (runs goaccess every 6 hours and updates the mmdb every wednesday at 18:30)
Adding the script to the container, can be done with volumes. Running it at container start is prepending it to the startup commands... CLI
docker compose
So the complete compose file looks like this:
run with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
My usecase for goaccess is primarily to satisfy my curiousity about who tries to access my self hosted services. As I am an enthusiastic docker user, I started using the goaccess docker image with the
--real-time-html
parameter.After getting everything setup and studying the report (really looking forward to the filtering options btw.), I realized that
--real-time-html
is actually overkill for my occasional curiousity. A daily update or perhaps 4 updates per day would be enough.That's where the idea below came from.
Periodic update of static report
Using goaccess as a pure CLI tool, one would create a cron-job to generate a periodic html-report. This can be done both with goaccess installed and with goaccess in a container. The crontabs entry could look like this:
or (as docker cli - WARNING, NOT TESTED!)
with
GOACCESS_ARGS
containing the proper arguments for goaccess.Goaccess container with cron daemon
If your philosophy is 'a container for the job', and you want 'the job' to be 'generating a report at regular intervals', the container needs to do this, not the docker host.
Luckily
crond
and a few other tools exist in the official goaccess container image. Utilizing it becomes a matter of overriding the entrypoint, replacing it with a shell, and then run a command that sets up a cron job to run goaccess and then runcrond
in the foreground.Technical solution
All is done in one (rather long) docker run command:
Breakdown in words:
Run the container, providing paths for the html-report, the config-file, the crontab file and the log files. Set the arguments for goaccess in an environment variable (makes it available both in shell in and cron). Override the entrypoint and run both goaccess and crond at container start.
Breakdown per line:
The content of /path/to/crontabs/root decides what the cron daemon runs. The content to run goaccess with the arguments every 6 hours looks like this:
That's how I use the official goaccess docker image to host and run a recurring generation of the html report.
As a side note, it parses
*.json.log
in my case every time, so if log files are added or removed, they will be included or left out at each invocation of goaccess that happens via the cron daemon. For me, this is a workaround for the problem described here: #2465 (comment)Beta Was this translation helpful? Give feedback.
All reactions