mirror of
https://github.com/prymitive/karma
synced 2026-05-11 03:46:48 +00:00
feat(backend): add metric alertmanager_up
If last api call failed, the metric is 0, otherwise 1
This commit is contained in:
committed by
Łukasz Mierzwa
parent
90d54c738a
commit
4205c13df5
@@ -10,6 +10,7 @@ type karmaCollector struct {
|
||||
collectedGroups *prometheus.Desc
|
||||
cyclesTotal *prometheus.Desc
|
||||
errorsTotal *prometheus.Desc
|
||||
alertmanagerUp *prometheus.Desc
|
||||
}
|
||||
|
||||
func newKarmaCollector() *karmaCollector {
|
||||
@@ -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{},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user