-
Notifications
You must be signed in to change notification settings - Fork 647
/
metrics.go
40 lines (33 loc) · 1.05 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package health
import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/prometheus/client_golang/prometheus"
)
// metrics reports commonly used health check metrics.
type metrics struct {
// log reports anomalous events.
log logging.Logger
// failingChecks keeps track of the number of check failing
failingChecks prometheus.Gauge
}
func newMetrics(log logging.Logger, namespace string, registerer prometheus.Registerer) (*metrics, error) {
metrics := &metrics{
log: log,
failingChecks: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "checks_failing",
Help: "number of currently failing health checks",
}),
}
return metrics, registerer.Register(metrics.failingChecks)
}
// healthy handles the metrics for the healthy cases
func (m *metrics) healthy() {
m.failingChecks.Dec()
}
// unHealthy handles the metrics for the unhealthy cases
func (m *metrics) unHealthy() {
m.failingChecks.Inc()
}