From b8f807c01f440052aa954992bda54cd5b3efd479 Mon Sep 17 00:00:00 2001 From: James O'Gorman Date: Sat, 28 Nov 2020 14:20:58 +0000 Subject: [PATCH] Add aaisp_scrape_success gauge Previously if we fail to connect to CHAOS during a scrape no metrics are emitted. Now a aaisp_scrape_success metric is always emitted with values 0 for failure and 1 for success, along the lines of blackbox_exporter's probe_success metric. --- cmd/aaisp_exporter/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/aaisp_exporter/main.go b/cmd/aaisp_exporter/main.go index 1821876..9d7b3cf 100644 --- a/cmd/aaisp_exporter/main.go +++ b/cmd/aaisp_exporter/main.go @@ -37,6 +37,10 @@ var ( []string{"line_id"}, nil, ) + scrapeSuccessGauge = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "aaisp_scrape_success", + Help: "Displays whether or not the AAISP API scrape was a success", + }) ) type broadbandCollector struct { @@ -51,8 +55,10 @@ func (bc broadbandCollector) Collect(ch chan<- prometheus.Metric) { lines, err := bc.BroadbandInfo() if err != nil { log.Printf("error getting broadband info: %v\n", err) + scrapeSuccessGauge.Set(0) return } + scrapeSuccessGauge.Set(1) for _, line := range lines { ch <- prometheus.MustNewConstMetric( broadbandQuotaRemainingDesc, @@ -93,6 +99,7 @@ func main() { } prometheus.MustRegister(collector) + prometheus.MustRegister(scrapeSuccessGauge) http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(*listen, nil)) }