github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/engine.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/onflow/flow-go/module"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  	"github.com/prometheus/client_golang/prometheus/promauto"
     8  )
     9  
    10  type EngineCollector struct {
    11  	sent            *prometheus.CounterVec
    12  	received        *prometheus.CounterVec
    13  	handled         *prometheus.CounterVec
    14  	inboundDropped  *prometheus.CounterVec
    15  	outboundDropped *prometheus.CounterVec
    16  }
    17  
    18  var _ module.EngineMetrics = (*EngineCollector)(nil)
    19  
    20  func NewEngineCollector() *EngineCollector {
    21  
    22  	ec := &EngineCollector{
    23  
    24  		sent: promauto.NewCounterVec(prometheus.CounterOpts{
    25  			Name:      "messages_sent_total",
    26  			Namespace: namespaceNetwork,
    27  			Subsystem: subsystemEngine,
    28  			Help:      "the number of messages sent by engines",
    29  		}, []string{EngineLabel, LabelMessage}),
    30  
    31  		received: promauto.NewCounterVec(prometheus.CounterOpts{
    32  			Name:      "messages_received_total",
    33  			Namespace: namespaceNetwork,
    34  			Subsystem: subsystemEngine,
    35  			Help:      "the number of messages received by engines",
    36  		}, []string{EngineLabel, LabelMessage}),
    37  
    38  		handled: promauto.NewCounterVec(prometheus.CounterOpts{
    39  			Name:      "messages_handled_total",
    40  			Namespace: namespaceNetwork,
    41  			Subsystem: subsystemEngine,
    42  			Help:      "the number of messages handled by engines",
    43  		}, []string{EngineLabel, LabelMessage}),
    44  
    45  		inboundDropped: promauto.NewCounterVec(prometheus.CounterOpts{
    46  			Name:      "inbound_messages_dropped_total",
    47  			Namespace: namespaceNetwork,
    48  			Subsystem: subsystemEngine,
    49  			Help:      "the number of inbound messages dropped by engines",
    50  		}, []string{EngineLabel, LabelMessage}),
    51  
    52  		outboundDropped: promauto.NewCounterVec(prometheus.CounterOpts{
    53  			Name:      "outbound_messages_dropped_total",
    54  			Namespace: namespaceNetwork,
    55  			Subsystem: subsystemEngine,
    56  			Help:      "the number of outbound messages dropped by engines",
    57  		}, []string{EngineLabel, LabelMessage}),
    58  	}
    59  
    60  	return ec
    61  }
    62  
    63  func (ec *EngineCollector) MessageSent(engine string, message string) {
    64  	ec.sent.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
    65  }
    66  
    67  func (ec *EngineCollector) MessageReceived(engine string, message string) {
    68  	ec.received.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
    69  }
    70  
    71  func (ec *EngineCollector) MessageHandled(engine string, message string) {
    72  	ec.handled.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
    73  }
    74  
    75  func (ec *EngineCollector) InboundMessageDropped(engine string, message string) {
    76  	ec.inboundDropped.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
    77  }
    78  
    79  func (ec *EngineCollector) OutboundMessageDropped(engine string, message string) {
    80  	ec.outboundDropped.With(prometheus.Labels{EngineLabel: engine, LabelMessage: message}).Inc()
    81  }