From b57e6a2e05979847baa12503aa67b7ca4fea0e10 Mon Sep 17 00:00:00 2001 From: Jake Herbst Date: Mon, 3 Oct 2022 10:20:29 -0400 Subject: [PATCH] Adding warning logging if full metrics set is not available. This will inform the user that pi-hole auth is missing or incorrect and some metrics will be missing from the exporter --- internal/pihole/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/pihole/client.go b/internal/pihole/client.go index 683961e..a72a998 100644 --- a/internal/pihole/client.go +++ b/internal/pihole/client.go @@ -125,6 +125,12 @@ func (c *Client) setMetrics(stats *Stats) { } metrics.Status.WithLabelValues(c.config.PIHoleHostname).Set(float64(isEnabled)) + // Pi-Hole returns a subset of stats when Auth is missing or incorrect. + // This provides a warning to users that metrics are not complete. + if len(stats.TopQueries) == 0 { + log.Warnf("Invalid Authentication - Some metrics may be missing. Please confirm your PI-Hole API token / Password for %s", c.config.PIHoleHostname) + } + for domain, value := range stats.TopQueries { metrics.TopQueries.WithLabelValues(c.config.PIHoleHostname, domain).Set(float64(value)) }