generated from cybozu-go/neco-template
/
metrics.go
98 lines (86 loc) · 3.28 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
metricsNamespace = "moco"
clusteringSubsystem = "cluster"
)
// Clustering related metrics
var (
CheckCountVec *prometheus.CounterVec
ErrorCountVec *prometheus.CounterVec
AvailableVec *prometheus.GaugeVec
HealthyVec *prometheus.GaugeVec
SwitchoverCountVec *prometheus.CounterVec
FailoverCountVec *prometheus.CounterVec
TotalReplicasVec *prometheus.GaugeVec
ReadyReplicasVec *prometheus.GaugeVec
ErrantReplicasVec *prometheus.GaugeVec
)
// Register registers Prometheus metrics vectors to the registry.
func Register(registry prometheus.Registerer) {
CheckCountVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "checks_total",
Help: "The number of times MOCO has checked the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(CheckCountVec)
ErrorCountVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "errors_total",
Help: "The number of times MOCO has got errors from the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(ErrorCountVec)
AvailableVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "available",
Help: "The cluster status about available condition",
}, []string{"name", "namespace"})
registry.MustRegister(AvailableVec)
HealthyVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "healthy",
Help: "The cluster status about healthy condition",
}, []string{"name", "namespace"})
registry.MustRegister(HealthyVec)
SwitchoverCountVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "switchover_total",
Help: "The total count of switchover in the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(SwitchoverCountVec)
FailoverCountVec = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "failover_total",
Help: "The total count of failover in the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(FailoverCountVec)
TotalReplicasVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "replicas",
Help: "The number of instances in the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(TotalReplicasVec)
ReadyReplicasVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "ready_replicas",
Help: "The number of ready Pods in the cluster",
}, []string{"name", "namespace"})
registry.MustRegister(ReadyReplicasVec)
ErrantReplicasVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: clusteringSubsystem,
Name: "errant_replicas",
Help: "The number of instances that have errant transactions",
}, []string{"name", "namespace"})
registry.MustRegister(ErrantReplicasVec)
}