github.com/ethersphere/bee/v2@v2.2.0/pkg/transaction/wrapped/metrics.go (about)

     1  // Copyright 2021 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package wrapped
     6  
     7  import (
     8  	m "github.com/ethersphere/bee/v2/pkg/metrics"
     9  	"github.com/prometheus/client_golang/prometheus"
    10  )
    11  
    12  type metrics struct {
    13  	TotalRPCCalls  prometheus.Counter
    14  	TotalRPCErrors prometheus.Counter
    15  
    16  	TransactionReceiptCalls prometheus.Counter
    17  	TransactionCalls        prometheus.Counter
    18  	BlockNumberCalls        prometheus.Counter
    19  	BlockHeaderCalls        prometheus.Counter
    20  	BalanceCalls            prometheus.Counter
    21  	CodeAtCalls             prometheus.Counter
    22  	NonceAtCalls            prometheus.Counter
    23  	PendingNonceCalls       prometheus.Counter
    24  	CallContractCalls       prometheus.Counter
    25  	SuggestGasPriceCalls    prometheus.Counter
    26  	EstimateGasCalls        prometheus.Counter
    27  	SendTransactionCalls    prometheus.Counter
    28  	FilterLogsCalls         prometheus.Counter
    29  	ChainIDCalls            prometheus.Counter
    30  }
    31  
    32  func newMetrics() metrics {
    33  	subsystem := "eth_backend"
    34  
    35  	return metrics{
    36  		TotalRPCCalls: prometheus.NewCounter(prometheus.CounterOpts{
    37  			Namespace: m.Namespace,
    38  			Subsystem: subsystem,
    39  			Name:      "total_rpc_calls",
    40  			Help:      "Count of rpc calls",
    41  		}),
    42  		TotalRPCErrors: prometheus.NewCounter(prometheus.CounterOpts{
    43  			Namespace: m.Namespace,
    44  			Subsystem: subsystem,
    45  			Name:      "total_rpc_errors",
    46  			Help:      "Count of rpc errors",
    47  		}),
    48  		TransactionCalls: prometheus.NewCounter(prometheus.CounterOpts{
    49  			Namespace: m.Namespace,
    50  			Subsystem: subsystem,
    51  			Name:      "calls_transaction",
    52  			Help:      "Count of eth_getTransaction rpc calls",
    53  		}),
    54  		TransactionReceiptCalls: prometheus.NewCounter(prometheus.CounterOpts{
    55  			Namespace: m.Namespace,
    56  			Subsystem: subsystem,
    57  			Name:      "calls_transaction_receipt",
    58  			Help:      "Count of eth_getTransactionReceipt rpc errors",
    59  		}),
    60  		BlockNumberCalls: prometheus.NewCounter(prometheus.CounterOpts{
    61  			Namespace: m.Namespace,
    62  			Subsystem: subsystem,
    63  			Name:      "calls_block_number",
    64  			Help:      "Count of eth_blockNumber rpc calls",
    65  		}),
    66  		BlockHeaderCalls: prometheus.NewCounter(prometheus.CounterOpts{
    67  			Namespace: m.Namespace,
    68  			Subsystem: subsystem,
    69  			Name:      "calls_block_header",
    70  			Help:      "Count of eth_getBlockByNumber (header only) calls",
    71  		}),
    72  		BalanceCalls: prometheus.NewCounter(prometheus.CounterOpts{
    73  			Namespace: m.Namespace,
    74  			Subsystem: subsystem,
    75  			Name:      "calls_balance",
    76  			Help:      "Count of eth_getBalance rpc calls",
    77  		}),
    78  		CodeAtCalls: prometheus.NewCounter(prometheus.CounterOpts{
    79  			Namespace: m.Namespace,
    80  			Subsystem: subsystem,
    81  			Name:      "calls_code_at",
    82  			Help:      "Count of eth_getCode rpc calls",
    83  		}),
    84  		NonceAtCalls: prometheus.NewCounter(prometheus.CounterOpts{
    85  			Namespace: m.Namespace,
    86  			Subsystem: subsystem,
    87  			Name:      "calls_nonce_at",
    88  			Help:      "Count of eth_getTransactionCount (pending false) rpc calls",
    89  		}),
    90  		PendingNonceCalls: prometheus.NewCounter(prometheus.CounterOpts{
    91  			Namespace: m.Namespace,
    92  			Subsystem: subsystem,
    93  			Name:      "calls_pending_nonce_at",
    94  			Help:      "Count of eth_getTransactionCount (pending true) rpc calls",
    95  		}),
    96  		CallContractCalls: prometheus.NewCounter(prometheus.CounterOpts{
    97  			Namespace: m.Namespace,
    98  			Subsystem: subsystem,
    99  			Name:      "calls_eth_call",
   100  			Help:      "Count of eth_call rpc calls",
   101  		}),
   102  		SuggestGasPriceCalls: prometheus.NewCounter(prometheus.CounterOpts{
   103  			Namespace: m.Namespace,
   104  			Subsystem: subsystem,
   105  			Name:      "calls_suggest_gasprice",
   106  			Help:      "Count of eth_suggestGasPrice rpc calls",
   107  		}),
   108  		EstimateGasCalls: prometheus.NewCounter(prometheus.CounterOpts{
   109  			Namespace: m.Namespace,
   110  			Subsystem: subsystem,
   111  			Name:      "calls_estimate_gasprice",
   112  			Help:      "Count of eth_estimateGas rpc calls",
   113  		}),
   114  		SendTransactionCalls: prometheus.NewCounter(prometheus.CounterOpts{
   115  			Namespace: m.Namespace,
   116  			Subsystem: subsystem,
   117  			Name:      "calls_send_transaction",
   118  			Help:      "Count of eth_sendRawTransaction rpc calls",
   119  		}),
   120  		FilterLogsCalls: prometheus.NewCounter(prometheus.CounterOpts{
   121  			Namespace: m.Namespace,
   122  			Subsystem: subsystem,
   123  			Name:      "calls_filter_logs",
   124  			Help:      "Count of eth_getLogs rpc calls",
   125  		}),
   126  		ChainIDCalls: prometheus.NewCounter(prometheus.CounterOpts{
   127  			Namespace: m.Namespace,
   128  			Subsystem: subsystem,
   129  			Name:      "calls_chain_id",
   130  			Help:      "Count of eth_chainId rpc calls",
   131  		}),
   132  	}
   133  }
   134  
   135  func (b *wrappedBackend) Metrics() []prometheus.Collector {
   136  	return m.PrometheusCollectorsFromFields(b.metrics)
   137  }