This is a script and associated Docker tooling to help collect metrics from Pihole's API and send them to an Influxdb for trending / custom reporting.
Configure the environment section of docker-compose.yaml accordingly and:
docker-compose up -d
HOSTNAME = "pihole"
PIHOLE_API = "http://192.168.2.20/admin/api.php"
INFLUXDB_SERVER = "192.168.2.5"
INFLUXDB_PORT = 8086
INFLUXDB_USERNAME = "telegraf"
INFLUXDB_PASSWORD = "telegraf"
INFLUXDB_DATABASE = "telegraf"
DELAY = 10
VERIFY_SSL = False
docker build -t pihole_stats:latest .
docker run --restart=always -d -e METRIC_DELAY=10 \
-e PIHOLE_API="http://192.168.2.22/admin/api.php" \
-e INFLUXDB_SERVER='192.168.2.10' \
-e INFLUXDB_DATABASE='telegraf' \
pihole_stats:latest
There is a supervisord.conf file included in the main source dir.
- Install supervisor. apt|yum|pip install supervisor
- Add the pihole_stats.py script into /opt/scripts/ directory.
- Run 'chmod +x /opt/scripts/pihole_stats.py'
- Use the provided supervisord.conf file or add:
[program:pihole_stats]
command=python /opt/scripts/pihole_stats.py
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_errfile=/var/log/supervisor/%(program_name)s.log
startsecs=0
exitcodes=0,1
autostart=true
autorestart=false
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
- Restart supervisord daemon to read in the new configuration if it is running.
- Confirm pihole_stats is running correctly using:
supervisorctl status
tail -f /var/log/supervisor/pihole_stats.log
https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux
- Confirm all needed python modules are installed. (requests and influxdb)
- Manually run your command= section in the container by using docker exec.
- Check the log files under /var/log/supervisor/ for errors.
- Edit script directly and change configuration variables or dynamically configure using environment variables.
sysadminnotes.ca