PiHole Monitoring
Monitoring your pihole stats will let you see if there any abnormalities on your network. You can show the data in a way that makes sense to you, set up alerts when they go outside of expected ranges. Then with other stats of other devices on grafana, you can really visualize all the interworkings of your network.
Steps
-
Install Grafana, Telegraf and InfluxDB if not already installed
sudo apt install -y grafana telegraf influxdb -
Create database on influx for pihole, to get to influx just enter
influxand you will be taken to the influx CLI.CREATE DATABASE pihole -
Create telegraf user and password on influxdb, this will be used on all telegraf uses and will just report to a specific database
user create -n <username> -p <password> -
On the pi go to /etc/telegraf/telegraf.d/
cd /etc/telegraf/telegraf.d/ -
Then create an input file called inputs.pihole.conf
touch inputs.pihole.conf -
Paste this code but dont forget to change the X.X.X.X to your pihole IP address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[[inputs.http]] #pihole URL for data in json format urls=["http://x.x.x.x:8080/admin/api.php"] method = "GET" #Overwrite measurement name from default http to pihole_stats name_override = "pihole_stats" #exclude 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 -
Then create an outputs.influxdb.conf file in the same location.
touch outputs.influx.conf -
You should put your creds into the /etc/defaults/telegraf file and when telegraf starts it is meant to grab the variables from there.
1 2 3
# INFLUX_URL = "http://x.x.x.x:8086" # INFLUX_USER = "telegraf" # INFLUX_PWD = "telegraf"
NOTE: This part was not working for me but I will update when I find an answer. I still recommend you do this as it is the secure way of doing it. Only come back and change it if, you run into issues.
-
In the outputs.influxdb.conf this is what the contents is meant to look like it. Replace the database with the name you gave your database.
1 2 3 4 5 6 7
[[outputs.influxdb]] urls = ["${INFLUX_URL}"] database = "pihole" ## HTTP Basic Auth username = "${INFLUX_USER}" password = "${INFLUX_PWD}" namepass = ["pihole_stats*"] -
Since I have not gotten this part to work yet, you can replace the info with the actual information that it is. Then you will want to run
telegraf --testto make sure everything works. Once that is working you will want to restart telegraf. -
Login into grafana which will be the ip you installed it on with port 3000.
X.X.X.X:3000if it is your first time login on, follow the instructions to create a user. -
On grafana you will want to add telegraf as a datasource and fill in the information. Choose method GET at the bottom.
![grafana settings]()
![grafana get]()
-
Then you can test the database to make sure it works
![grafana test]()
-
After that you will create a new panel, I picked the guage to visualize but you can pick whatever panel you want to show your data
-
Select your database and then the stat, then what you want to show. and you are done! Now to add some spice.
-
Change the colors for the different percentages and then you will know if you are blocking a lot of domains or a normal amount.
![grafana visual]()



