Pi-hole InfluxDB Data Collector

This script is written in Python and thus needs Python to be installed on the host you wish to run it on.

Running the script on the Pi-hole host.

1. Install Python pip

sudo apt-get install python-pip -y

2. Create a new directory for the script to live in.

mkdir /opt/pihole-influx

3. Clone the Pi-hole script repo.

git clone /opt/pihole-influx

4. Once that finishes, cd to /pihole-influx and run:

pip install -r requirements.txt
5. Now clone the config.example.ini to config.ini.
cp config.example.ini config.ini

6. Edit the config.ini file to match your environment.

nano config.ini
port <influxdb port>
hostname <ip.of.influx.db>
username <influxdb username for pihole db>
password <influxdb password for pihole db>
database <db name for pihole in influxdb>
api_location address of the /admin/api.php of your pi-hole instance
instance_name <hostname>

You can scrape multiple pi-hole instances if you run more than 1 by adding a second config block called [pihole_2].

You'll need to create the database, in InfluxDB, for the pi-hole stats. See here for how to create a new database.

You can start the script by running ./ in your script directory. 

Running the script as a service

1. Create the service file

nano piholeinflux.service

2. Add the following to the .service file

ExecStart=/usr/bin/python /path/to/pihole-influx/

3. Create the service link

sudo ln -s /opt/pihole-influx/piholeinflux.service /etc/systemd/system

4. Enable the service and reload the service daemon

sudo systemctl enable piholeinflux.service && sudo systemctl daemon-reload

5. Start the piholeinflux service

sudo systemctl start piholeinflux.service

If you get an error while running make sure you can A: communicate to InfluxDB and B: the “USER=” in the .service file is set to a user that can run it (i.e. root or you).

You can check the service status by running: sudo systemctl status piholeinflux.service

Running the script as a Docker container

1. Copy the Dockerfile and config.ini into the same folder

FROM alpine as builder
RUN apk add --no-cache git
RUN git clone
FROM python:3-alpine
WORKDIR /usr/src/app
COPY --from=builder /app/pi-hole-influx/requirements.txt /usr/src/app
RUN pip install --no-cache-dir -r requirements.txt
COPY --from=builder /app/pi-hole-influx/ /usr/src/app
COPY config.ini .
CMD [ "python", "./" ]
port = 8086
hostname =
username = pihole
password = allthosesweetstatistics
database = pihole
# Time between reports to InfluxDB (in seconds)
reporting_interval = 10
api_location =
instance_name = pihole
timeout = 10

2. Edit the config.ini to match your environment.

(Can use above steps to see what needs changed)

3. Build the container.

Note: You will have to be in the same subdirectory as the Dockerfile in order for it to build using the below command!

docker build -t your-name/of-image .

4. Deploy the container

docker run --name Pi-Hole_Influx your-name/of-image -d

You can combine the docker run and build commands but pointing docker run to the Dockerfile. This will build and deploy the container!

Back to top