From e31a0fa0365256a395f7962892e3fb00b5b4b348 Mon Sep 17 00:00:00 2001 From: Steve Berg Date: Mon, 4 Jul 2016 12:53:30 -0500 Subject: [PATCH] Updated Stats monitoring in check_mk_agent (markdown) --- Stats-monitoring-in-check_mk_agent.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Stats-monitoring-in-check_mk_agent.md b/Stats-monitoring-in-check_mk_agent.md index 0cde07c..b2bd2d8 100644 --- a/Stats-monitoring-in-check_mk_agent.md +++ b/Stats-monitoring-in-check_mk_agent.md @@ -1,6 +1,6 @@ I've written this extremely simple local check for the check_mk_agent. If you've installed the agent on your Pi-Hole place this into an executable file wherever your check_mk_agent expects to find local plugins. Alternatively this could be installed on any system that has access to the Pi-Hole console, I decided to put it on the Pi-Hole directly. I named mine "mk_pihole_stats.py" but as long as it's in the correct subdirectory and the agent script can execute it it should work just fine. -After you reinventory the client where you installed this you should have two new local checks. PiHole_Ads and PiHole_Percent. +After you reinventory the client where you installed this you should have three new local checks. PiHole_Ads, PiHole_Percent and PiHole_Queries. #!/usr/bin/python # Simple (always OK) check_mk local check to track # of ads blocked today. @@ -9,23 +9,32 @@ After you reinventory the client where you installed this you should have two ne import urllib2 import json - + import re + # Define your Pi-Hole console address console = "http://192.168.1.2/admin/" - + try: url = console + "api.php" result = urllib2.urlopen(url, timeout = 5).read() json = json.loads(result) + count = json['ads_blocked_today'] - print "0 PiHole_Ads blocked=" + count + " OK " + count + " ads blocked today." + count2 = re.sub(',', '', count) + print "0 PiHole_Ads ads_blocked=" + count2 + " OK - " + count + " ads blocked today." + pct = json['ads_percentage_today'] - print "0 PiHole_Percent percent=" + pct + " OK " + pct + "%." + print "0 PiHole_Percent ads_percent=" + pct + " OK - " + pct + "% of dns requests were for ad domains." + queries = json['dns_queries_today'] + queries2 = re.sub(',', '', queries) + print "0 PiHole_DNS queries=" + queries2 + " OK " + queries + " DNS queries today." + except: print "3 PiHole_Ads Unknown" -After the logs rotated for the first time since I started using this check the ads_blocked_today perf data zero'd out. I'm not quite sure why yet though, check_mk should still see previous values even if current values are zero. -I'll probably let it run for a few more days without modifying anything to see if it was a temporary glitch or if I've done something wrong here. Added: After the next log rotation the stats behaved as I expected them to. Once I get a week of stats I'll post the performance graphs that pnp4nagios generates. \ No newline at end of file + +After the logs rotated for the first time since I started using this check the ads_blocked_today perf data zero'd out. I'm not quite sure why yet though, check_mk should still see previous values even if current values are zero. +Found the problem. The script was returning ads_blocked and queries values with commas "," in them. Check_mk doesn't like that. So I've stripped the comma out of each returned number and it looks much better now. \ No newline at end of file