[SOLVED] Displaying Pi-Hole stats in Conky

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
nyteshyft
Level 1
Level 1
Posts: 20
Joined: Sat Sep 18, 2021 11:37 pm

[SOLVED] Displaying Pi-Hole stats in Conky

Post by nyteshyft »

Hello all,

Instead of having the web dashboard open all the time, I'd like to display the Pi-Hole stats via Conky. Is this possible? A quick search on the internet doesn't bring up any results other than https://www.reddit.com/r/pihole/comment ... ole_conky/ but it doesn't give me any code I can put into conky.conf

I'm actually surprised that nobody has done this before. The web dashboard is great but I don't want the browser open all the time, and I know I can use the CLI and display it like that, but again, I want it fixed into conky with the basic stats.

Any suggestions?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Displaying Pi-Hole stats in Conky

Post by zcot »

In that link you show, there's a posted link to a deviantart solution, it is a conky config, in fact the one you are looking at.
nyteshyft
Level 1
Level 1
Posts: 20
Joined: Sat Sep 18, 2021 11:37 pm

Re: Displaying Pi-Hole stats in Conky

Post by nyteshyft »

zcot wrote: Tue Oct 19, 2021 5:34 pm In that link you show, there's a posted link to a deviantart solution, it is a conky config, in fact the one you are looking at.
Yes, I originally clicked on it and I couldn't find where to download it, it sends you to deviantart. I just went there again and realised that I had to create a deviantart account in order to download the script. However, the script doesn't work.

Here is the script. I took it from that download and added it to my conky.conf file but it doesn't display the stats.

Code: Select all

DNS 1${alignr}${execi 1000 nmcli device show wlp3s0 | grep DNS  | awk 'NR==1 {print $2}'}
DNS 2${alignr}${execi 1000 nmcli device show wlp3s0 | grep DNS  | awk 'NR==2 {print $2}'}$font
#
${execi 60 curl pi.hole/admin/api.php | sed 's/.$//' > ~/.cache/pi.txt}${alignc}Pi-Hole stats:
${voffset 5}${exec awk -F '[:,]' '{print \ 
"DNS Queries Today: "$4"\n" \
"Queries Blocked: "$6"\n" \
"Total Domains Blocked: "$2"\n" \
"Queries Forwarded: "$12"\n" \
"Queries Cached: "$14"\n" \
"Unique Clients: "$16 }' ~/.cache/pi.txt
Shouldn't there be some sort of login to the API to get these stats? I can see it uses curl to try to access pi.hole but shouldn't there be some form of username:password login info in there somewhere?
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Displaying Pi-Hole stats in Conky

Post by zcot »

pi.hole will be defined on your network if your machine is set to use that dns, so it will do the query and save the results locally and use that to populate the data in the next lines.

You are not doing anything admin-wise, so no login/password.

You should look at the first 2 lines where is says wlp3s0.

You can check with the terminal command: nmcli device status to find some active device that you should be using in place of that wlp3s0 device name.
nyteshyft
Level 1
Level 1
Posts: 20
Joined: Sat Sep 18, 2021 11:37 pm

Re: Displaying Pi-Hole stats in Conky

Post by nyteshyft »

Yeah I figured that out, I changed that from "wlp3s0" to "enp3s0". It now displays the PiHole DNS and my router gateway, but none of the stats.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Displaying Pi-Hole stats in Conky

Post by zcot »

you can run that on terminal to see any info: curl pi.hole/admin/api.php
nyteshyft
Level 1
Level 1
Posts: 20
Joined: Sat Sep 18, 2021 11:37 pm

Re: Displaying Pi-Hole stats in Conky

Post by nyteshyft »

zcot wrote: Thu Oct 21, 2021 8:02 am you can run that on terminal to see any info: curl pi.hole/admin/api.php
That command didn't return a result:

Code: Select all

$ curl pi.hole/admin/api.php
curl: (6) Could not resolve host: pi.hole
So I replaced "pi.hole/admin/api.php" with "192.168.1.192/admin/api.php" which gave me this:

Code: Select all

$ curl 192.168.1.192/admin/api.php
{"domains_being_blocked":93465,"dns_queries_today":18836,"ads_blocked_today":3290,"ads_percentage_today":17.466553,"unique_domains":1704,"queries_forwarded":10961,"queries_cached":4229,"clients_ever_seen":12,"unique_clients":10,"dns_queries_all_types":18836,"reply_NODATA":2764,"reply_NXDOMAIN":246,"reply_CNAME":8127,"reply_IP":7289,"privacy_level":0,"status":"enabled","gravity_last_updated":{"file_exists":true,"absolute":1634601633,"relative":{"days":2,"hours":21,"minutes":31}}}
So I changed that line in conky.conf but it still isn't displaying the stats.
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: Displaying Pi-Hole stats in Conky

Post by zcot »

You changed the formatting around on the config and it broke it. ;)

there's the original:

Code: Select all

${execi 60 curl pi.hole/admin/api.php | sed 's/.$//' > ~/.cache/pi.txt}${alignc}Pi-Hole stats:
${voffset 5}${exec awk -F '[:,]' '{print \
"Domains Blocked: "$2"\n" \
"DNS Queries Today: "$4"\n" \
"Queries Blocked: "$6 " - (" int($8)"%)\n" \
"Queries Forwarded: "$12"\n" \
"Queries Cached: "$14"\n" \
"Unique Clients: "$16'} ~/.cache/pi.txt}
You need to be checking the line that says Queries Blocked, for accuracy, and mainly that last line, Unique Clients, you did something to change the total of the ${exec} command, and maybe it's making awk puke, but either way the exec is failing because of that quote mark.
nyteshyft
Level 1
Level 1
Posts: 20
Joined: Sat Sep 18, 2021 11:37 pm

Re: Displaying Pi-Hole stats in Conky

Post by nyteshyft »

That worked, thank you!
User avatar
zcot
Level 9
Level 9
Posts: 2832
Joined: Wed Oct 19, 2016 6:08 pm

Re: [SOLVED] Displaying Pi-Hole stats in Conky

Post by zcot »

You are welcome! :)
Locked

Return to “Compiz, Conky, Docks & Widgets”