github.com/koko1123/flow-go-1@v0.29.6/module/metrics/access.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 AccessCollector struct {
     9  	connectionReused      prometheus.Counter
    10  	connectionsInPool     *prometheus.GaugeVec
    11  	connectionAdded       prometheus.Counter
    12  	connectionEstablished prometheus.Counter
    13  	connectionInvalidated prometheus.Counter
    14  	connectionUpdated     prometheus.Counter
    15  	connectionEvicted     prometheus.Counter
    16  }
    17  
    18  func NewAccessCollector() *AccessCollector {
    19  	ac := &AccessCollector{
    20  		connectionReused: promauto.NewCounter(prometheus.CounterOpts{
    21  			Name:      "connection_reused",
    22  			Namespace: namespaceAccess,
    23  			Subsystem: subsystemConnectionPool,
    24  			Help:      "counter for the number of times connections get reused",
    25  		}),
    26  		connectionsInPool: promauto.NewGaugeVec(prometheus.GaugeOpts{
    27  			Name:      "connections_in_pool",
    28  			Namespace: namespaceAccess,
    29  			Subsystem: subsystemConnectionPool,
    30  			Help:      "counter for the number of connections in the pool against max number tne pool can hold",
    31  		}, []string{"result"}),
    32  		connectionAdded: promauto.NewCounter(prometheus.CounterOpts{
    33  			Name:      "connection_added",
    34  			Namespace: namespaceAccess,
    35  			Subsystem: subsystemConnectionPool,
    36  			Help:      "counter for the number of times connections are added to the pool",
    37  		}),
    38  		connectionEstablished: promauto.NewCounter(prometheus.CounterOpts{
    39  			Name:      "connection_established",
    40  			Namespace: namespaceAccess,
    41  			Subsystem: subsystemConnectionPool,
    42  			Help:      "counter for the number of times connections are established",
    43  		}),
    44  		connectionInvalidated: promauto.NewCounter(prometheus.CounterOpts{
    45  			Name:      "connection_invalidated",
    46  			Namespace: namespaceAccess,
    47  			Subsystem: subsystemConnectionPool,
    48  			Help:      "counter for the number of times connections are invalidated",
    49  		}),
    50  		connectionUpdated: promauto.NewCounter(prometheus.CounterOpts{
    51  			Name:      "connection_updated",
    52  			Namespace: namespaceAccess,
    53  			Subsystem: subsystemConnectionPool,
    54  			Help:      "counter for the number of times existing connections from the pool are updated",
    55  		}),
    56  		connectionEvicted: promauto.NewCounter(prometheus.CounterOpts{
    57  			Name:      "connection_evicted",
    58  			Namespace: namespaceAccess,
    59  			Subsystem: subsystemConnectionPool,
    60  			Help:      "counter for the number of times a cached connection is evicted from the connection pool",
    61  		}),
    62  	}
    63  
    64  	return ac
    65  }
    66  
    67  func (ac *AccessCollector) ConnectionFromPoolReused() {
    68  	ac.connectionReused.Inc()
    69  }
    70  
    71  func (ac *AccessCollector) TotalConnectionsInPool(connectionCount uint, connectionPoolSize uint) {
    72  	ac.connectionsInPool.WithLabelValues("connections").Set(float64(connectionCount))
    73  	ac.connectionsInPool.WithLabelValues("pool_size").Set(float64(connectionPoolSize))
    74  }
    75  
    76  func (ac *AccessCollector) ConnectionAddedToPool() {
    77  	ac.connectionAdded.Inc()
    78  }
    79  
    80  func (ac *AccessCollector) NewConnectionEstablished() {
    81  	ac.connectionEstablished.Inc()
    82  }
    83  
    84  func (ac *AccessCollector) ConnectionFromPoolInvalidated() {
    85  	ac.connectionInvalidated.Inc()
    86  }
    87  
    88  func (ac *AccessCollector) ConnectionFromPoolUpdated() {
    89  	ac.connectionUpdated.Inc()
    90  }
    91  
    92  func (ac *AccessCollector) ConnectionFromPoolEvicted() {
    93  	ac.connectionEvicted.Inc()
    94  }