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

     1  package metrics
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  	"github.com/prometheus/client_golang/prometheus/promauto"
     8  )
     9  
    10  type LoaderCollector struct {
    11  	transactionsSent prometheus.Counter
    12  	transactionsLost prometheus.Counter
    13  	tpsConfigured    prometheus.Gauge
    14  
    15  	transactionsExecuted prometheus.Counter
    16  	tteInSeconds         prometheus.Histogram
    17  }
    18  
    19  func NewLoaderCollector() *LoaderCollector {
    20  
    21  	cc := &LoaderCollector{
    22  		transactionsSent: promauto.NewCounter(prometheus.CounterOpts{
    23  			Name:      "transactions_sent",
    24  			Namespace: namespaceLoader,
    25  			Help:      "transactions sent by the loader",
    26  		}),
    27  		transactionsLost: promauto.NewCounter(prometheus.CounterOpts{
    28  			Name:      "transactions_lost",
    29  			Namespace: namespaceLoader,
    30  			Help:      "transaction that took too long to return",
    31  		}),
    32  		tpsConfigured: promauto.NewGauge(prometheus.GaugeOpts{
    33  			Name:      "transactions_per_second_configured",
    34  			Namespace: namespaceLoader,
    35  			Help:      "transactions per second that the loader should send",
    36  		}),
    37  		transactionsExecuted: promauto.NewCounter(prometheus.CounterOpts{
    38  			Name:      "transactions_executed",
    39  			Namespace: namespaceLoader,
    40  			Help:      "transaction successfully executed by the loader",
    41  		}),
    42  		tteInSeconds: promauto.NewHistogram(prometheus.HistogramOpts{
    43  			Name:      "transactions_executed_in_seconds",
    44  			Namespace: namespaceLoader,
    45  			Help:      "Time To Execute histogram for transactions (in seconds)",
    46  			Buckets:   prometheus.ExponentialBuckets(2, 2, 8),
    47  		}),
    48  	}
    49  
    50  	return cc
    51  }
    52  
    53  func (cc *LoaderCollector) TransactionSent() {
    54  	cc.transactionsSent.Inc()
    55  }
    56  
    57  func (cc *LoaderCollector) TransactionLost() {
    58  	cc.transactionsLost.Inc()
    59  }
    60  
    61  func (cc *LoaderCollector) SetTPSConfigured(tps uint) {
    62  	cc.tpsConfigured.Set(float64(tps))
    63  }
    64  
    65  func (cc *LoaderCollector) TransactionExecuted(duration time.Duration) {
    66  	cc.transactionsExecuted.Inc()
    67  	cc.tteInSeconds.Observe(float64(duration.Seconds()))
    68  }