Skip to content
A python daemon to send Pi-Hole stats for Grafana to InfluxDB
Branch: master
Clone or download
Latest commit c0a528c May 1, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.readme-assets Add Grafana dashboard.json file and screenshot Jun 22, 2018
tests Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
.codeclimate.yml Complete test coverage, overall overhaul (#15) Mar 2, 2019
.coveragerc
.flake8 Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
.gitignore Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
.gitlab-ci.yml Another latest fix May 1, 2019
.travis.yml Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
Dockerfile Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
README.md
dashboard.json Add Grafana dashboard.json file and screenshot Jun 22, 2018
default.toml Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
piholeinflux.py Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
piholeinflux.service Little cleanup, default to python3 in setup and .service Feb 9, 2019
pyproject.toml Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
pytest.ini Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
requirements-tests.txt Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
requirements.txt Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019
user.toml.example Add Dockerfile and CI builds, general config overhaul (#18) May 1, 2019

README.md

Pi-hole-Influx

Build Status Maintainability Coverage Status Code style: black

A simple daemonized script to report Pi-Hole stats to an InfluxDB, ready to be displayed via Grafana.

Heads-up: the configuration options changed fundamentally in recent versions. Please read up on the current state below.

Example Grafana Dashboard

Setup (Using Docker)

To use docker for running the daemon, use the following command:

docker run \
  -e PIHOLE_INFLUXDB_HOST="myhostname" \
  -e PIHOLE_INFLUXDB_PORT="8086" \
  -e PIHOLE_INFLUXDB_USERNAME="myusername" \
  -e PIHOLE_INFLUXDB_PASSWORD="mysupersecretpassword" \
  -e PIHOLE_INFLUXDB_DATABASE="pihole" \
  -e PIHOLE_INSTANCES="localhost=http://127.0.0.1/admin/api.php" \
  registry.gitlab.com/janw/pi-hole-influx

The following values are the defaults and will be used if not set:

  • PIHOLE_INFLUXDB_PORT="8086"
  • PIHOLE_INFLUXDB_HOST="127.0.0.1"
  • PIHOLE_INFLUXDB_DATABASE="pihole"
  • PIHOLE_INSTANCES="localhost=http://127.0.0.1/admin/api.php"

PIHOLE_INSTANCES contains the Pi-hole instances that are to be reported. Multiple instances can given in a dict-like boxed syntax, known as Inline Tables in TOML:

PIHOLE_INSTANCES="{first_one="http://127.0.0.1/admin/api.php",second_pihole="http://192.168.42.79/admin/api.php"[,…]}"

Note that instances are prefixed by a custom name.

Setup (Traditional Way)

As Pi-hole (as the name suggests) is built specifically with the Raspberry Pi in mind (and I run it on there as well), the following steps assume an instance of Pi-hole on Raspbian Strech Lite, with no additional modifications so far. Piholestatus will be configured to run on the same Pi.

First install the necessary packages via apt as Raspbian Lite does have neither git nor pip installed.

sudo apt update
sudo apt install git python3-pip -y

Now clone the repo, install the Python dependencies, and make sure to copy and adjust the example configuation file to match your setup.

git clone https://github.com/janw/pi-hole-influx.git ~/pi-hole-influx
cd ~/pi-hole-influx

# Install requirements via pip
pip3 install -r requirements.txt

# Copy config.example and modify it (should be self-explanatory)
cp user.toml.example user.toml
vi user.toml

Before starting the daemon for the first time, symlink the systemd service into place, reload, and enable the service.

sudo ln -s /home/pi/pi-hole-influx/piholeinflux.service /etc/systemd/system/
sudo systemctl --system daemon-reload
sudo systemctl enable piholeinflux.service

Now you're ready to start the daemon. Wait a few seconds to check its status.

sudo systemctl start piholeinflux.service
sudo systemctl status piholeinflux.service

The status should look as follows. Note the Status: line showing the last time, the daemon reported to InfluxDB:

● piholeinflux.service - Pi-hole-Influx - Send Pi-hole statistics to InfluxDB for visualization
   Loaded: loaded (/home/pi/pi-hole-influx/piholeinflux.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-06-22 19:03:56 UTC; 10min ago
     Docs: https://github.com/janw/pi-hole-influx
 Main PID: 21329 (python)
   Status: "Reported to InfluxDB at 2018-06-22 19:14:09 +0000"
   CGroup: /system.slice/piholeinflux.service
           └─21329 /usr/bin/python /home/pi/pi-hole-influx/piholeinflux.py

Set up a Grafana Dashboard

The example dashboard seen at the top uses the collected data and displays it in concise and sensible graphs and single stats. The dashboard can be imported into your Grafana instance from the dashboard.json file included in the repo, or by using ID 6603 to import it from Grafana's Dashboard Directory.

Attributions

The script originally created by Jon Hayward, adapted to work with InfluxDB by /u/tollsjo in December 2016, and improved and extended by @johnappletree. "If I have seen further it is by standing on the shoulders of giants". 🤓

You can’t perform that action at this time.