From faae635c0cdbb58698299ce24139d81139ec9274 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Wed, 27 Nov 2019 22:31:46 -0800 Subject: [PATCH] track zeros --- poller/prometheus.go | 4 ++-- promunifi/collector.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/poller/prometheus.go b/poller/prometheus.go index c811ef47..b53f7c62 100644 --- a/poller/prometheus.go +++ b/poller/prometheus.go @@ -42,8 +42,8 @@ func (u *UnifiPoller) LogExportReport(report *promunifi.Report) { u.Logf("UniFi Measurements Exported. Sites: %d, Clients: %d, "+ "Wireless APs: %d, Gateways: %d, Switches: %d%s, Descs: %d, "+ - "Metrics: %d, Errors: %d, Elapsed: %v", + "Metrics: %d, Errors: %d, Zeros: %d, Elapsed: %v", len(m.Sites), len(m.Clients), len(m.UAPs), len(m.UDMs)+len(m.USGs), len(m.USWs), idsMsg, report.Descs, report.Total, report.Errors, - report.Elapsed.Round(time.Millisecond)) + report.Zeros, report.Elapsed.Round(time.Millisecond)) } diff --git a/promunifi/collector.go b/promunifi/collector.go index f5b00a9b..0ea3e588 100644 --- a/promunifi/collector.go +++ b/promunifi/collector.go @@ -50,6 +50,7 @@ type metricExports struct { type Report struct { Total int Errors int + Zeros int Descs int Metrics *metrics.Metrics Elapsed time.Duration @@ -140,22 +141,29 @@ func (u *unifiCollector) exportMetrics(ch chan<- prometheus.Metric, r *Report) { for _, m := range newMetrics { r.Total++ descs[m.Desc] = true + var value float64 switch v := m.Value.(type) { case unifi.FlexInt: - ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, v.Val, m.Labels...) + value = v.Val case float64: - ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, v, m.Labels...) + value = v case int64: - ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, float64(v), m.Labels...) + value = float64(v) case int: - ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, float64(v), m.Labels...) + value = float64(v) default: r.Errors++ if u.Config.ReportErrors { ch <- prometheus.NewInvalidMetric(m.Desc, fmt.Errorf("not a number: %v", m.Value)) } + continue } + + if value == 0 { + r.Zeros++ + } + ch <- prometheus.MustNewConstMetric(m.Desc, m.ValueType, value, m.Labels...) } r.wg.Done() }