-
Notifications
You must be signed in to change notification settings - Fork 178
/
engine.go
81 lines (64 loc) · 2.69 KB
/
engine.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
package metrics
import (
"github.com/onflow/flow-go/module"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type EngineCollector struct {
sent *prometheus.CounterVec
received *prometheus.CounterVec
handled *prometheus.CounterVec
inboundDropped *prometheus.CounterVec
outboundDropped *prometheus.CounterVec
}
var _ module.EngineMetrics = (*EngineCollector)(nil)
func NewEngineCollector() *EngineCollector {
ec := &EngineCollector{
sent: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "messages_sent_total",
Namespace: namespaceNetwork,
Subsystem: subsystemEngine,
Help: "the number of messages sent by engines",
}, []string{EngineLabel, LabelMessage}),
received: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "messages_received_total",
Namespace: namespaceNetwork,
Subsystem: subsystemEngine,
Help: "the number of messages received by engines",
}, []string{EngineLabel, LabelMessage}),
handled: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "messages_handled_total",
Namespace: namespaceNetwork,
Subsystem: subsystemEngine,
Help: "the number of messages handled by engines",
}, []string{EngineLabel, LabelMessage}),
inboundDropped: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "inbound_messages_dropped_total",
Namespace: namespaceNetwork,
Subsystem: subsystemEngine,
Help: "the number of inbound messages dropped by engines",
}, []string{EngineLabel, LabelMessage}),
outboundDropped: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "outbound_messages_dropped_total",
Namespace: namespaceNetwork,
Subsystem: subsystemEngine,
Help: "the number of outbound messages dropped by engines",
}, []string{EngineLabel, LabelMessage}),
}
return ec
}
func (ec *EngineCollector) MessageSent(engine string, message string) {
ec.sent.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
}
func (ec *EngineCollector) MessageReceived(engine string, message string) {
ec.received.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
}
func (ec *EngineCollector) MessageHandled(engine string, message string) {
ec.handled.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
}
func (ec *EngineCollector) InboundMessageDropped(engine string, message string) {
ec.inboundDropped.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
}
func (ec *EngineCollector) OutboundMessageDropped(engine string, message string) {
ec.outboundDropped.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
}