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.
This commit is contained in:
James O'Gorman
2020-11-28 14:20:58 +00:00
parent d38a72627f
commit b8f807c01f

View File

@@ -37,6 +37,10 @@ var (
[]string{"line_id"}, []string{"line_id"},
nil, 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 { type broadbandCollector struct {
@@ -51,8 +55,10 @@ func (bc broadbandCollector) Collect(ch chan<- prometheus.Metric) {
lines, err := bc.BroadbandInfo() lines, err := bc.BroadbandInfo()
if err != nil { if err != nil {
log.Printf("error getting broadband info: %v\n", err) log.Printf("error getting broadband info: %v\n", err)
scrapeSuccessGauge.Set(0)
return return
} }
scrapeSuccessGauge.Set(1)
for _, line := range lines { for _, line := range lines {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
broadbandQuotaRemainingDesc, broadbandQuotaRemainingDesc,
@@ -93,6 +99,7 @@ func main() {
} }
prometheus.MustRegister(collector) prometheus.MustRegister(collector)
prometheus.MustRegister(scrapeSuccessGauge)
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*listen, nil)) log.Fatal(http.ListenAndServe(*listen, nil))
} }