github.com/koko1123/flow-go-1@v0.29.6/module/metrics/engine.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 ) 7 8 type EngineCollector struct { 9 sent *prometheus.CounterVec 10 received *prometheus.CounterVec 11 handled *prometheus.CounterVec 12 } 13 14 func NewEngineCollector() *EngineCollector { 15 16 ec := &EngineCollector{ 17 18 sent: promauto.NewCounterVec(prometheus.CounterOpts{ 19 Name: "messages_sent_total", 20 Namespace: namespaceNetwork, 21 Subsystem: subsystemEngine, 22 Help: "the number of messages sent by engines", 23 }, []string{EngineLabel, LabelMessage}), 24 25 received: promauto.NewCounterVec(prometheus.CounterOpts{ 26 Name: "messages_received_total", 27 Namespace: namespaceNetwork, 28 Subsystem: subsystemEngine, 29 Help: "the number of messages received by engines", 30 }, []string{EngineLabel, LabelMessage}), 31 32 handled: promauto.NewCounterVec(prometheus.CounterOpts{ 33 Name: "messages_handled_total", 34 Namespace: namespaceNetwork, 35 Subsystem: subsystemEngine, 36 Help: "the number of messages handled by engines", 37 }, []string{EngineLabel, LabelMessage}), 38 } 39 40 return ec 41 } 42 43 func (ec *EngineCollector) MessageSent(engine string, message string) { 44 ec.sent.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc() 45 } 46 47 func (ec *EngineCollector) MessageReceived(engine string, message string) { 48 ec.received.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc() 49 } 50 51 func (ec *EngineCollector) MessageHandled(engine string, message string) { 52 ec.handled.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc() 53 }