forked from segmentio/redis-go
/
monitor.go
42 lines (36 loc) · 1017 Bytes
/
monitor.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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
// A Monitor defines metrics for gRPC
type Monitor struct {
dialer *prometheus.CounterVec
server *Matrix
}
// NewMonitor creates Monitor for starting
func NewMonitor(subsystem string, labels prometheus.Labels) *Monitor {
dialer := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "redis",
Subsystem: subsystem,
Name: "reconnects_total",
Help: "Total number of reconnects made by server to redis back server.",
ConstLabels: labels,
},
[]string{"local_addr", "remote_addr"},
)
return &Monitor{
dialer: dialer,
server: NewServerMatrix(subsystem, labels),
}
}
// Describe implements prometheus Collector interface.
func (m *Monitor) Describe(in chan<- *prometheus.Desc) {
m.dialer.Describe(in)
m.server.Describe(in)
}
// Collect implements prometheus Collector interface.
func (m *Monitor) Collect(in chan<- prometheus.Metric) {
m.dialer.Collect(in)
m.server.Collect(in)
}