ezmrtg is a Docker-based MRTG (Multi Router Traffic Grapher) monitoring solution that simplifies network device monitoring via SNMP. The application runs in an Alpine Linux container with nginx, MRTG, PHP-FPM, and automated monitoring scripts.
The Docker container orchestrates multiple services via the CMD in Dockerfile:17:
- PHP-FPM starts for dynamic content serving
- nginx starts with custom config for serving MRTG data
- crond starts to run periodic MRTG updates
- wrapper.sh executes to initialize MRTG configuration and start monitoring
- nginx access logs are tailed for container logging
Host configuration is managed through environment variables and shell scripts:
-
Initial Setup (
wrapper.sh): Orchestrates the initialization sequence- Reads SNMP_HOSTS from environment variable
- Generates MRTG config files per host
- Updates host-specific configurations
- Starts MRTG daemons
- Creates HTML index files
-
Host Management: SNMP hosts are parsed from space-separated SNMP_HOSTS environment variable
- Format:
IP_ADDRESSorIP_ADDRESS:COMMUNITY_STRING - Default community string is "public" if not specified
- Each host gets its own cfg file and data directory
- Format:
-
Configuration Variables (
scripts/config): All scripts source this file for paths- MRTG_ROOT="/mrtg"
- DIRCFG="/mrtg/cfg"
- DIRHTML="/mrtg"
- CWD="/mrtg/scripts"
MRTG runs one daemon per monitored host (not centralized):
- Each host has its own .cfg file in /mrtg/cfg/
- Each daemon writes data to /mrtg/data/{hostname}/
- Lock files (.cfg_l) prevent duplicate daemons
- Update script runs every minute via cron (/etc/periodic/1min)
The web UI uses HTML frames (index.html:2-5):
- Left frame (150px): Navigation showing all monitored hosts
- Main frame: MRTG graphs and statistics
- Generated via indexmaker for per-host HTML
- Static file serving with PHP-FPM for dynamic content
Build the Docker image:
docker build -t ezmrtg .Run with docker-compose:
docker-compose up -dRun with docker directly:
docker run -d --rm --name ezmrtg \
-p 80:80 \
-v /path/to/mrtg/cfg:/mrtg/cfg \
-v /path/to/mrtg/data:/mrtg/data \
-e SNMP_HOSTS='192.168.1.1 192.168.1.2:private' \
legolator/ezmrtgAccess running container:
docker exec -it ezmrtg bashView logs:
docker logs -f ezmrtgCheck nginx logs inside container:
docker exec ezmrtg tail -f /var/log/nginx/mrtg.access.log
docker exec ezmrtg tail -f /var/log/nginx/mrtg.error.logCheck MRTG host logs inside container:
docker exec ezmrtg cat /mrtg/cfg/{hostname}.logManually trigger MRTG update for all hosts:
docker exec ezmrtg /mrtg/scripts/update-mrtg.shRegenerate configuration for new hosts:
docker exec ezmrtg /mrtg/scripts/make-cfg.shRegenerate index files:
docker exec ezmrtg /mrtg/scripts/make-index.shRegenerate left navigation:
docker exec ezmrtg /mrtg/scripts/make-left.shTo add new SNMP hosts without recreating the container, update the SNMP_HOSTS environment variable and restart. With persistent volumes, existing data is preserved.
Note: SNMP_HOSTS is only required on initial run. After configuration files are created in the mounted cfg volume, they persist across container restarts.
Two volumes should be mounted for data persistence:
/mrtg/cfg: MRTG configuration files (one per host)/mrtg/data: MRTG historical data and graphs (one directory per host)
Without these volumes, all configuration and monitoring history is lost on container restart.
Dockerfile: Alpine-based container setup with nginx, MRTG, PHP-FPMmrtg.conf: nginx configuration serving MRTG content on port 80crontabs: Cron schedule running MRTG updates every minutescripts/wrapper.sh: Initialization script orchestrating setupscripts/config: Shared path configuration sourced by all scriptsscripts/hosts: Generated from SNMP_HOSTS environment variablescripts/make-cfg.sh: Generates MRTG config files using cfgmakerscripts/start-mrtg.sh: Starts MRTG daemons in daemon modescripts/update-mrtg.sh: Updates MRTG data (called by cron)scripts/make-index.sh: Generates per-host index.html filesscripts/make-left.sh: Generates navigation frame with host links
Two docker-compose configurations are provided:
docker-compose.yaml: Standard deployment with direct port mappingdocker-compose-with-traefik.yaml: Integration with Traefik reverse proxy
For Traefik deployment, update the Host rule in the labels to match your domain.