Skip to content

vlauciani/docker-awstats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License GitHub issues

Docker Cloud Build Status Docker Image Size (latest semver) Docker Pulls

docker-awstats

Awstats Docker Image.

Pre-built docker image is available on Docker Hub.

Credits

This Docker setup is based on work from: https://github.com/justb4/docker-awstats.

Awstats Documentation

Quickstart

Clone the repository

First, clone the git repositry:

$ git clone https://github.com/vlauciani/docker-awstats.git
$ cd docker-awstats

Docker image

To obtain docker-awstats docker image, you have two options:

1) Get built image from DockerHub (preferred)

Get the last built image from DockerHub repository:

$ docker pull vlauciani/docker-awstats:latest

2) Build by yourself

$ docker build --tag vlauciani/docker-awstats . 

in case of errors, try:

$ docker build --no-cache --pull --tag vlauciani/docker-awstats . 

Get last Docker image:

$ cd docker-awstats
$ docker pull vlauciani/docker-awstats

Starts an example

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

Starts in PRODUCTION in detached (backgroud) mode

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

Design

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 (via cron)
  • 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 with envsubst 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 via AWSTATS_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.

Advanced

User-defined Scripts

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.

Analyze old log files

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}"

Contribute

Please, feel free to contribute.

Author

(c) 2020 Valentino Lauciani valentino.lauciani[at]ingv.it

Istituto Nazionale di Geofisica e Vulcanologia, Italia

About

AWStats docker container

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published