From 6cdcc48e6b7d72677c4b9025df0c4402e2f9856a Mon Sep 17 00:00:00 2001 From: Steve Berg Date: Sat, 31 Dec 2016 14:18:03 -0600 Subject: [PATCH] Updated Stats monitoring in check_mk_agent (markdown) --- Stats-monitoring-in-check_mk_agent.md | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Stats-monitoring-in-check_mk_agent.md b/Stats-monitoring-in-check_mk_agent.md index bdf7c7d..8ec0e07 100644 --- a/Stats-monitoring-in-check_mk_agent.md +++ b/Stats-monitoring-in-check_mk_agent.md @@ -39,6 +39,40 @@ After you reinventory the client where you installed this you should have three 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. +Just re-wrote this in perl, only because I'm more comforatable working with perl. There's three modules you'll need to ensure are available for this to work. + + #!/usr/bin/perl + use LWP::Simple; + use JSON; + use Data::Dumper; + + # api output: + # {"domains_being_blocked":"104,574","dns_queries_today":"37,188","ads_blocked_today":"708","ads_percentage_today":"1.9" } + # + # Convert json to perl array: + # $VAR1 = { + # 'domains_being_blocked' => '104,574', + # 'ads_percentage_today' => '1.9', + # 'ads_blocked_today' => '716', + # 'dns_queries_today' => '37,496' + # }; + + my $data = get("http://192.168.1.2/admin/api.php"); + + $data1 = decode_json $data; + + $pct = $data1->{ads_percentage_today}; + $blocked = $data1->{ads_blocked_today}; + $dns = $data1->{dns_queries_today}; + + $blocked =~ s/,//g; + $dns =~ s/,//g; + + print "0 PiHole_Ads ads_blocked=$blocked OK $blocked ads blocked today\n"; + print "0 PiHole_Percent ads_percent=$pct OK ${pct}% of dns requests were for ad domains\n"; + print "0 PiHole_DNS queries=$dns OK $dns DNS queries today\n"; + + Example graphs: ![Ads blocked - 1 week](https://github.com/BiloxiGeek/Contributions/blob/master/ads-blocked-1week.png)