If you want to be informed about your Pi-Hole statistics, but don’t want to visit the Pi-Hole dashboard all the time, then there is also an alternative way to get the statistics out of Pi-Hole, and use the numbers to present it in any other way that meets your demands. This could be e.g. showing it on a display (like the Scroll pHAT HD), uploading it to ThingSpeak, or whatever else you can think of.
Pi-Hole already provides you the opportunity to make a request for getting some statistic data right out of the box. You just have to put the following line in the address bar of your browser and replace IPOFYOURPIRUNNINGPIHOLE with the IP address of your Raspberry Pi, on which Pi-Hole is running, and you will get a list with various numbers and the description for them.
The result is given to you in the JSON data format and can easily be processed with Python, just like shown in previous scripts here in the blog before.
The following small Python script gets the data, extracts some interesting information, formats it, and then outputs the final text on the command line.
#!/usr/bin/env python import json import urllib2 try: f = urllib2.urlopen('http://IPOFYOURPIRUNNINGPIHOLE/admin/api.php') json_string = f.read() parsed_json = json.loads(json_string) queries = parsed_json['dns_queries_today'] adsblocked = parsed_json['ads_blocked_today'] clients = parsed_json['unique_clients'] f.close() except: queries = '-' adsblocked = '-' clients = '-' pihole = 'DNS-Queries: ' + str(queries) + ' - ' + 'Ads blocked: ' + str(adsblocked) + ' - ' + 'Devices: ' + str(clients) print pihole