Looking for the Perfect Dashboard: InfluxDB, Telegraf, and Grafana – Part XXIX (Monitoring Pi-hole)

Greetings friends, it has been a while since I expanded the series of In Search of the Perfect Dashboard, but it has taken time to continue. Today I bring you a very interesting entry, which I really wanted to add to the series, it’s about how to collect Pi-hole statistics.

Once we finish all the steps, you should have a result similar to the following:As you may know, if you use Pi-hole, the default interface of the solution is given an air.

What is Pi-hole?

Pi-Hole is an ad blocker that works at the DNS level protecting all our network. In a domestic environment, you can cut almost all the ads from all the devices in our house, without having to install an ad blocker in each one of them.

In simple terms, a DNS server is an Internet address record that helps locate the server using the domain name. When you visit any site, you make a query to the DNS server to locate the IP address (location) of the server you are connecting to. Pi-Hole is placed between our device and an upstream DNS server (maybe your Active Directory, or typical 8.8.8.8) and blocks any requests to known ad and tracking servers. Pi-Hole can accept DNS queries but depends on an upstream server to resolve the queries.

Some of the incredible features and advantages of Pi Hole:

  • Free! All you need is a device to run Pi-Hole on – A Raspberry Pi, Linux Machine, or Docker.
  • No client-side ad-blocking software is required.
  • Over 100,000 ad service domains blocked with the default blocking lists.
  • Blocks ads on any device, including smart TVs and other devices that do not allow any modification. The exception is devices with hard-coded DNS (explained below).
  • It reduces bandwidth and improves overall network performance. As you can see in the image above. More than 50% of ad requests were blocked before being downloaded.
  • Pi-Hole has a built-in web server that provides an easy to use web interface for administration.

We won’t see how to install it today, because it’s really only 5 minutes, but we’ll see how to monitor it, so let’s go! To get the information, I haven’t used complex scripts that require authentication, I have directly used the api.php that gives us the necessary data.

Configuring the Telegraf to scan the new .json and send it to InfluxDB

This time I will use the always versatile inputs.http, to analyze directly from the .json, the configuration couldn’t be easier, I have created a new file under /etc/telegraf/telegraf.d/pihole.conf with this inside, change only the URL to your Pi-hole:

[[inputs.http]]
#PiHole URL for data in JSON format
urls = ["http://192.168.1.3/admin/api.php"]
method = "GET"

#Overwrite measurement name from default `http` to `pihole_stats`
name_override = "pihole_stats"

#Exclude url and host items from tags
tagexclude = ["host"]

#Data from HTTP in JSON format
data_format = "json"

#JSON values to set as string fields
json_string_fields = ["url", "status"]

insecure_skip_verify = true

To test that everything works, please run the next command:

telegraf --config /etc/telegraf/telegraf.d/pihole.conf --test

The normal output of the command, if everything works as expected, might be something similar to this:

pihole_stats,ads_blocked_today=1946,ads_percentage_today=7.122987,clients_ever_seen=11,dns_queries_all_types=27320,dns_queries_today=27320,domains_being_blocked=131435,privacy_level=0,queries_cached=6864,queries_forwarded=18510,reply_CNAME=5149,reply_IP=8706,reply_NODATA=3177,reply_NXDOMAIN=2312,unique_clients=11,unique_domains=3122 gravity_last_updated_absolute=1607834043,gravity_last_updated_relative_days=1,gravity_last_updated_relative_hours=9,gravity_last_updated_relative_minutes=17,status="enabled" 1607953895000000000

Let’s go and restart the telegraf service with this simple command:

systemctl restart telegraf

If we now move to our Grafana – Explorer, we will be able to see new data:

Dashboard to see everything centrally

Now that we have all this information, we probably want to show it in a more elegant way.

Just by importing the next Dashboard using the Grafana URL, you will already have something similar to this:

At the end of the day, if everything has gone well, you will be able to see your great Pi-hole Dashboard and know how many requests you are saving, and show everyone how you have improved the quality and security of the network: That’s all folks, if you want to follow the full Blog series about Grafana, InfluxDB, Telegraf, please click on the next links:

Author: jorgeuk

Father, writing in https://www.jorgedelacruz.es and https://jorgedelacruz.uk Blogger, Systems Engineer @veeam - vExpert 2014/2020 & NTC 2018/19

2 Thoughts

  1. Thanks for the post. I have been thinking about adding custom feeds to Telegraf/InfluxDB and your JSON example is very helpful. I’m building a section of my dashboard for important backyard chickens metrics like temperature, humidity, and whether the water heater turned on or not 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.