github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/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/platformvm/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) AddValidatorTx(*txs.AddValidatorTx) error {
    38  	m.numTxs.With(prometheus.Labels{
    39  		txLabel: "add_validator",
    40  	}).Inc()
    41  	return nil
    42  }
    43  
    44  func (m *txMetrics) AddSubnetValidatorTx(*txs.AddSubnetValidatorTx) error {
    45  	m.numTxs.With(prometheus.Labels{
    46  		txLabel: "add_subnet_validator",
    47  	}).Inc()
    48  	return nil
    49  }
    50  
    51  func (m *txMetrics) AddDelegatorTx(*txs.AddDelegatorTx) error {
    52  	m.numTxs.With(prometheus.Labels{
    53  		txLabel: "add_delegator",
    54  	}).Inc()
    55  	return nil
    56  }
    57  
    58  func (m *txMetrics) CreateChainTx(*txs.CreateChainTx) error {
    59  	m.numTxs.With(prometheus.Labels{
    60  		txLabel: "create_chain",
    61  	}).Inc()
    62  	return nil
    63  }
    64  
    65  func (m *txMetrics) CreateSubnetTx(*txs.CreateSubnetTx) error {
    66  	m.numTxs.With(prometheus.Labels{
    67  		txLabel: "create_subnet",
    68  	}).Inc()
    69  	return nil
    70  }
    71  
    72  func (m *txMetrics) ImportTx(*txs.ImportTx) error {
    73  	m.numTxs.With(prometheus.Labels{
    74  		txLabel: "import",
    75  	}).Inc()
    76  	return nil
    77  }
    78  
    79  func (m *txMetrics) ExportTx(*txs.ExportTx) error {
    80  	m.numTxs.With(prometheus.Labels{
    81  		txLabel: "export",
    82  	}).Inc()
    83  	return nil
    84  }
    85  
    86  func (m *txMetrics) AdvanceTimeTx(*txs.AdvanceTimeTx) error {
    87  	m.numTxs.With(prometheus.Labels{
    88  		txLabel: "advance_time",
    89  	}).Inc()
    90  	return nil
    91  }
    92  
    93  func (m *txMetrics) RewardValidatorTx(*txs.RewardValidatorTx) error {
    94  	m.numTxs.With(prometheus.Labels{
    95  		txLabel: "reward_validator",
    96  	}).Inc()
    97  	return nil
    98  }
    99  
   100  func (m *txMetrics) RemoveSubnetValidatorTx(*txs.RemoveSubnetValidatorTx) error {
   101  	m.numTxs.With(prometheus.Labels{
   102  		txLabel: "remove_subnet_validator",
   103  	}).Inc()
   104  	return nil
   105  }
   106  
   107  func (m *txMetrics) TransformSubnetTx(*txs.TransformSubnetTx) error {
   108  	m.numTxs.With(prometheus.Labels{
   109  		txLabel: "transform_subnet",
   110  	}).Inc()
   111  	return nil
   112  }
   113  
   114  func (m *txMetrics) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error {
   115  	m.numTxs.With(prometheus.Labels{
   116  		txLabel: "add_permissionless_validator",
   117  	}).Inc()
   118  	return nil
   119  }
   120  
   121  func (m *txMetrics) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error {
   122  	m.numTxs.With(prometheus.Labels{
   123  		txLabel: "add_permissionless_delegator",
   124  	}).Inc()
   125  	return nil
   126  }
   127  
   128  func (m *txMetrics) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error {
   129  	m.numTxs.With(prometheus.Labels{
   130  		txLabel: "transfer_subnet_ownership",
   131  	}).Inc()
   132  	return nil
   133  }
   134  
   135  func (m *txMetrics) BaseTx(*txs.BaseTx) error {
   136  	m.numTxs.With(prometheus.Labels{
   137  		txLabel: "base",
   138  	}).Inc()
   139  	return nil
   140  }