-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
51 lines (46 loc) · 1.38 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
package pingpong
import (
"github.com/prometheus/client_golang/prometheus"
m "github.com/redesblock/mop/core/metrics"
)
type metrics struct {
// all metrics fields must be exported
// to be able to return them by Metrics()
// using reflection
PingSentCount prometheus.Counter
PongSentCount prometheus.Counter
PingReceivedCount prometheus.Counter
PongReceivedCount prometheus.Counter
}
func newMetrics() metrics {
subsystem := "pingpong"
return metrics{
PingSentCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "ping_sent_count",
Help: "Number ping requests sent.",
}),
PongSentCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pong_sent_count",
Help: "Number of pong responses sent.",
}),
PingReceivedCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "ping_received_count",
Help: "Number ping requests received.",
}),
PongReceivedCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pong_received_count",
Help: "Number of pong responses received.",
}),
}
}
func (s *Service) Metrics() []prometheus.Collector {
return m.PrometheusCollectorsFromFields(s.metrics)
}