github.com/koko1123/flow-go-1@v0.29.6/module/metrics/observer.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  	"github.com/prometheus/client_golang/prometheus/promauto"
     6  	"google.golang.org/grpc/codes"
     7  )
     8  
     9  type ObserverCollector struct {
    10  	rpcs *prometheus.CounterVec
    11  }
    12  
    13  func NewObserverCollector() *ObserverCollector {
    14  	return &ObserverCollector{
    15  		rpcs: promauto.NewCounterVec(prometheus.CounterOpts{
    16  			Namespace: namespaceObserver,
    17  			Subsystem: subsystemObserverGRPC,
    18  			Name:      "handler_grpc_counter",
    19  			Help:      "tracking error/success rate of each rpc for the observer service",
    20  		}, []string{"handler", "grpc_method", "grpc_code"}),
    21  	}
    22  }
    23  
    24  func (oc *ObserverCollector) RecordRPC(handler, rpc string, code codes.Code) {
    25  	oc.rpcs.With(prometheus.Labels{
    26  		"handler":     handler,
    27  		"grpc_method": rpc,
    28  		"grpc_code":   code.String(),
    29  	}).Inc()
    30  }