Skip to content

Commit

Permalink
feat(backend): add metric alertmanager_up
Browse files Browse the repository at this point in the history
If last api call failed, the metric is 0, otherwise 1
  • Loading branch information
carlpett authored and prymitive committed Sep 25, 2020
1 parent 90d54c7 commit 4205c13
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/karma/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type karmaCollector struct {
collectedGroups *prometheus.Desc
cyclesTotal *prometheus.Desc
errorsTotal *prometheus.Desc
alertmanagerUp *prometheus.Desc
}

func newKarmaCollector() *karmaCollector {
Expand Down Expand Up @@ -38,6 +39,12 @@ func newKarmaCollector() *karmaCollector {
[]string{"alertmanager", "endpoint"},
prometheus.Labels{},
),
alertmanagerUp: prometheus.NewDesc(
"karma_alertmanager_up",
"1 if last call to Alertmanager API succeeded",
[]string{"alertmanager"},
prometheus.Labels{},
),
}
}

Expand All @@ -46,6 +53,7 @@ func (c *karmaCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.collectedGroups
ch <- c.cyclesTotal
ch <- c.errorsTotal
ch <- c.alertmanagerUp
}

func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -117,9 +125,23 @@ func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) {
)
}
}

ch <- prometheus.MustNewConstMetric(
c.alertmanagerUp,
prometheus.GaugeValue,
boolToFloat64(am.Error() == ""),
am.Name,
)
}
}

func init() {
prometheus.MustRegister(newKarmaCollector())
}

func boolToFloat64(b bool) float64 {
if b {
return 1
}
return 0
}

0 comments on commit 4205c13

Please sign in to comment.