github.com/MetalBlockchain/metalgo@v1.11.9/vms/avm/metrics/tx_metrics.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package metrics
     5  
     6  import (
     7  	"github.com/prometheus/client_golang/prometheus"
     8  
     9  	"github.com/MetalBlockchain/metalgo/vms/avm/txs"
    10  )
    11  
    12  const txLabel = "tx"
    13  
    14  var (
    15  	_ txs.Visitor = (*txMetrics)(nil)
    16  
    17  	txLabels = []string{txLabel}
    18  )
    19  
    20  type txMetrics struct {
    21  	numTxs *prometheus.CounterVec
    22  }
    23  
    24  func newTxMetrics(registerer prometheus.Registerer) (*txMetrics, error) {
    25  	m := &txMetrics{
    26  		numTxs: prometheus.NewCounterVec(
    27  			prometheus.CounterOpts{
    28  				Name: "txs_accepted",
    29  				Help: "number of transactions accepted",
    30  			},
    31  			txLabels,
    32  		),
    33  	}
    34  	return m, registerer.Register(m.numTxs)
    35  }
    36  
    37  func (m *txMetrics) BaseTx(*txs.BaseTx) error {
    38  	m.numTxs.With(prometheus.Labels{
    39  		txLabel: "base",
    40  	}).Inc()
    41  	return nil
    42  }
    43  
    44  func (m *txMetrics) CreateAssetTx(*txs.CreateAssetTx) error {
    45  	m.numTxs.With(prometheus.Labels{
    46  		txLabel: "create_asset",
    47  	}).Inc()
    48  	return nil
    49  }
    50  
    51  func (m *txMetrics) OperationTx(*txs.OperationTx) error {
    52  	m.numTxs.With(prometheus.Labels{
    53  		txLabel: "operation",
    54  	}).Inc()
    55  	return nil
    56  }
    57  
    58  func (m *txMetrics) ImportTx(*txs.ImportTx) error {
    59  	m.numTxs.With(prometheus.Labels{
    60  		txLabel: "import",
    61  	}).Inc()
    62  	return nil
    63  }
    64  
    65  func (m *txMetrics) ExportTx(*txs.ExportTx) error {
    66  	m.numTxs.With(prometheus.Labels{
    67  		txLabel: "export",
    68  	}).Inc()
    69  	return nil
    70  }