Pihole stats -> InfluxDB

Will poll metrics from a Pihole server via lex-pihole and send it to an influxdb server.

Requirements - both the influxdb and pihole lex need to be installed on at least a single Legion node

Grab the functions

SELECT functions.id, extensions.name, runners.name, functions.name FROM `extensions` INNER JOIN runners on extensions.id = runners.extension_id INNER JOIN functions on runners.id = functions.runner_id WHERE extensions.name in ('pihole', 'influxdb') and runners.name IN ('writer', 'api') AND functions.name in ('summary', 'write_points') # pihole functions.id = 213 in this example # influxdb functions.id = 9 in this example
INSERT INTO chains (name, active) VALUES ('pihole stats to influxdb', 1); # replace chain_id 1 with the actual result INSERT INTO relationships (name, active, chain_id, trigger_id, action_id, transformation) VALUES ('pihole stats to influxdb', 1, 1, 213, 9, 'transformation from below'); # insert new schedule to make this thing run INSERT INTO schedules (function_id, active, `interval`, name, payload) VALUES (213, 1, 10, 'pihole query every 10 seconds', '{"host":"127.0.0.1", "port":80}');

Transformation to insert as json string

{ "host": "localhost", "port": 8086, "database": "pihole", "metrics": "{ \"tags\": { \"host\": \"127.0.0.1\" }, \"values\":{ \"domains_being_blocked\": <%= results[:domains_being_blocked].delete(',').to_i %>, \"dns_queries_today\": <%= results[:dns_queries_today].delete(',').to_i %>, \"ads_blocked_today\": <%= results[:ads_blocked_today].delete(',').to_i %>, \"ads_percentage_today\": <%= results[:ads_percentage_today].delete(',').to_f %>, \"unique_domains\": <%= results[:unique_domains].delete(',').to_i %>, \"queries_forwarded\": <%= results[:queries_forwarded].delete(',').to_i %>, \"queries_cached\": <%= results[:queries_cached].delete(',').to_i %>, \"clients_ever_seen\": <%= results[:clients_ever_seen].delete(',').to_i %>, \"unique_clients\": <%= results[:unique_clients].delete(',').to_i %>, \"dns_queries_all_types\": <%= results[:dns_queries_all_types].delete(',').to_i %>, \"reply_NODATA\": <%= results[:reply_NODATA].delete(',').to_i %>, \"reply_NXDOMAIN\": <%= results[:reply_NXDOMAIN].delete(',').to_i %>, \"reply_CNAME\": <%= results[:reply_CNAME].delete(',').to_i %>, \"reply_IP\": <%= results[:reply_IP].delete(',').to_i %>, \"privacy_level\": <%= results[:privacy_level].to_i %>, \"status\": \"<%= results[:status] %>\", } }" }