-
Notifications
You must be signed in to change notification settings - Fork 178
/
engine.go
53 lines (42 loc) · 1.59 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
package metrics
import (
"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
}
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}),
}
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()
}