Awstats Docker Image.
Pre-built docker image is available on Docker Hub.
This Docker setup is based on work from: https://github.com/justb4/docker-awstats.
First, clone the git repositry:
$ git clone https://github.com/vlauciani/docker-awstats.git
$ cd docker-awstats
To obtain docker-awstats docker image, you have two options:
Get the last built image from DockerHub repository:
$ docker pull vlauciani/docker-awstats:latest
$ docker build --tag vlauciani/docker-awstats .
in case of errors, try:
$ docker build --no-cache --pull --tag vlauciani/docker-awstats .
$ cd docker-awstats
$ docker pull vlauciani/docker-awstats
Prepare input conf and log:
$ cp data/sites/geotracing.com.conf.example data/sites/geotracing.com.conf
$ cp data/sites/conf.local.example data/sites/conf.local
$ cp data/log/geotracing-access.log.example data/log/geotracing-access.log
Start container:
$ docker run --name=docker-awstats -it --rm -p 8081:80 -v $(pwd)/data/sites:/etc/awstats/sites:ro -v $(pwd)/data/log:/var/local/log:ro -v $(pwd)/data/awstats:/var/lib/awstats vlauciani/docker-awstats
Connect to: http://localhost:8081
Note: The process to analize log files, starts every 10min. You can wait or open another shell and type:
$ docker exec -it docker-awstats aw-update.sh
To start in production, detach the container adding the -d
option:
$ docker run -d --name=docker-awstats -it --rm -p 8081:80 -v $(pwd)/data/sites:/etc/awstats/sites:ro -v $(pwd)/data/log:/var/local/log:ro -v $(pwd)/data/awstats:/var/lib/awstats vlauciani/docker-awstats
to view the logs:
$ docker logs -f docker-awstats
to stop:
$ docker stop docker-awstats
The intention is to have this Docker image as self-contained as possible in order to
avoid host-bound/specific actions and tooling, in particular log processing via
host-based cron
, we may even apply logrotate
later. Also allow for multiple domains with minimal config.
Further design choices:
- schedule
awstats
processing (viacron
) - allow for multiple domains
- generate a landing HTML page with links to stats of all domains
- allow for minimal config within an
.env
file (expand withenvsubst
into template.conf
) - allow full Awstats
.conf
file as well - have GeoIP reverse IP lookup, enabled (may need more advanced/detailed upgrade to...)
- configurable
subpath
(prefix) for running behind reverse proxy viaAWSTATS_PATH_PREFIX=
env var - make it easy run with docker-compose
A debian-slim
Docker Image ((buster
version) is used as base image.
(I'd love to use Alpine, but it became too complicated
with the above features, input welcome!).
The entry program is supervisord
that will run a setup program once, apache2
webserver daemon
(for the landing page and logstats), and cron
for Awstats processing.
User-defined Shell/Bash scripts can be added in the directories /aw-setup.d
and/or /aw-update.d
by extending
the Docker Image or easier via Docker Volume Mounting.
Purpose is to provide hooks for preprocessing. For example, a script that fetches/syncs a logfile from a remote server just before aw-update.sh runs. This ensures the data is available.
Awstats only processes lines in log files that are newer than the newest already
known line.
This means you cannot analyze older log files later. Start with oldest ones first.
You may need to delete already processed data by rm /var/lib/awstats/*
Example sketch of bash-script to process old Apache2 logfiles partly gzipped:
#!/bin/bash
#
# Run the app
#
#
# Example gzipped log files from mydomain.com-access.log.2 up to mydomain.com-access.log.60
LOGDIR="/var/local/log"
LOGNAME="access.log"
END=60
# Loop backwards 60,59,...2.
for i in $(seq $END -1 2)
do
logFile="${LOGDIR}/${LOGNAME}.${i}"
echo "i=${i} logFile=${logFile}"
docker exec -it awstats gunzip ${logFile}.gz
docker exec -it awstats awstats -config=mydomain.com -update -LogFile="${logFile}"
docker exec -it awstats gzip ${logFile}
done
# Non-zipped remaining files
docker exec -it awstats awstats -config=mydomain.com -update -LogFile="${LOGDIR}/${LOGNAME}.1"
docker exec -it awstats awstats -config=mydomain.com -update -LogFile="${LOGDIR}/${LOGNAME}"
Please, feel free to contribute.
(c) 2020 Valentino Lauciani valentino.lauciani[at]ingv.it
Istituto Nazionale di Geofisica e Vulcanologia, Italia