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

     1  // Copyright 2020 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 accounting
     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  	// all metrics fields must be exported
    14  	// to be able to return them by Metrics()
    15  	// using reflection
    16  	TotalDebitedAmount                       prometheus.Counter
    17  	TotalCreditedAmount                      prometheus.Counter
    18  	DebitEventsCount                         prometheus.Counter
    19  	CreditEventsCount                        prometheus.Counter
    20  	AccountingDisconnectsEnforceRefreshCount prometheus.Counter
    21  	AccountingRefreshAttemptCount            prometheus.Counter
    22  	AccountingNonFatalRefreshFailCount       prometheus.Counter
    23  	AccountingDisconnectsOverdrawCount       prometheus.Counter
    24  	AccountingDisconnectsGhostOverdrawCount  prometheus.Counter
    25  	AccountingDisconnectsReconnectCount      prometheus.Counter
    26  	AccountingBlocksCount                    prometheus.Counter
    27  	AccountingReserveCount                   prometheus.Counter
    28  	TotalOriginatedCreditedAmount            prometheus.Counter
    29  	OriginatedCreditEventsCount              prometheus.Counter
    30  	SettleErrorCount                         prometheus.Counter
    31  	PaymentAttemptCount                      prometheus.Counter
    32  	PaymentErrorCount                        prometheus.Counter
    33  	ErrTimeOutOfSyncAlleged                  prometheus.Counter
    34  	ErrTimeOutOfSyncRecent                   prometheus.Counter
    35  	ErrTimeOutOfSyncInterval                 prometheus.Counter
    36  	ErrRefreshmentBelowExpected              prometheus.Counter
    37  	ErrRefreshmentAboveExpected              prometheus.Counter
    38  }
    39  
    40  func newMetrics() metrics {
    41  	subsystem := "accounting"
    42  
    43  	return metrics{
    44  		TotalDebitedAmount: prometheus.NewCounter(prometheus.CounterOpts{
    45  			Namespace: m.Namespace,
    46  			Subsystem: subsystem,
    47  			Name:      "total_debited_amount",
    48  			Help:      "Amount of BZZ debited to peers (potential income of the node)",
    49  		}),
    50  		TotalCreditedAmount: prometheus.NewCounter(prometheus.CounterOpts{
    51  			Namespace: m.Namespace,
    52  			Subsystem: subsystem,
    53  			Name:      "total_credited_amount",
    54  			Help:      "Amount of BZZ credited to peers (potential cost of the node)",
    55  		}),
    56  		DebitEventsCount: prometheus.NewCounter(prometheus.CounterOpts{
    57  			Namespace: m.Namespace,
    58  			Subsystem: subsystem,
    59  			Name:      "debit_events_count",
    60  			Help:      "Number of occurrences of BZZ debit events towards peers",
    61  		}),
    62  		CreditEventsCount: prometheus.NewCounter(prometheus.CounterOpts{
    63  			Namespace: m.Namespace,
    64  			Subsystem: subsystem,
    65  			Name:      "credit_events_count",
    66  			Help:      "Number of occurrences of BZZ credit events towards peers",
    67  		}),
    68  		AccountingDisconnectsEnforceRefreshCount: prometheus.NewCounter(prometheus.CounterOpts{
    69  			Namespace: m.Namespace,
    70  			Subsystem: subsystem,
    71  			Name:      "disconnects_enforce_refresh_count",
    72  			Help:      "Number of occurrences of peers disconnected based on failed refreshment attempts",
    73  		}),
    74  		AccountingRefreshAttemptCount: prometheus.NewCounter(prometheus.CounterOpts{
    75  			Namespace: m.Namespace,
    76  			Subsystem: subsystem,
    77  			Name:      "refresh_attempt_count",
    78  			Help:      "Number of attempts of refresh op",
    79  		}),
    80  		AccountingNonFatalRefreshFailCount: prometheus.NewCounter(prometheus.CounterOpts{
    81  			Namespace: m.Namespace,
    82  			Subsystem: subsystem,
    83  			Name:      "non_fatal_refresh_fail_count",
    84  			Help:      "Number of occurrences of refreshments failing for peers because of peer timestamp ahead of ours",
    85  		}),
    86  		AccountingDisconnectsOverdrawCount: prometheus.NewCounter(prometheus.CounterOpts{
    87  			Namespace: m.Namespace,
    88  			Subsystem: subsystem,
    89  			Name:      "disconnects_overdraw_count",
    90  			Help:      "Number of occurrences of peers disconnected based on payment thresholds",
    91  		}),
    92  		AccountingDisconnectsGhostOverdrawCount: prometheus.NewCounter(prometheus.CounterOpts{
    93  			Namespace: m.Namespace,
    94  			Subsystem: subsystem,
    95  			Name:      "disconnects_ghost_overdraw_count",
    96  			Help:      "Number of occurrences of peers disconnected based on undebitable requests thresholds",
    97  		}),
    98  		AccountingDisconnectsReconnectCount: prometheus.NewCounter(prometheus.CounterOpts{
    99  			Namespace: m.Namespace,
   100  			Subsystem: subsystem,
   101  			Name:      "disconnects_reconnect_count",
   102  			Help:      "Number of occurrences of peers disconnected based on early attempt to reconnect",
   103  		}),
   104  
   105  		AccountingBlocksCount: prometheus.NewCounter(prometheus.CounterOpts{
   106  			Namespace: m.Namespace,
   107  			Subsystem: subsystem,
   108  			Name:      "accounting_blocks_count",
   109  			Help:      "Number of occurrences of temporarily skipping a peer to avoid crossing their disconnect thresholds",
   110  		}),
   111  		AccountingReserveCount: prometheus.NewCounter(prometheus.CounterOpts{
   112  			Namespace: m.Namespace,
   113  			Subsystem: subsystem,
   114  			Name:      "accounting_reserve_count",
   115  			Help:      "Number of reserve calls",
   116  		}),
   117  		TotalOriginatedCreditedAmount: prometheus.NewCounter(prometheus.CounterOpts{
   118  			Namespace: m.Namespace,
   119  			Subsystem: subsystem,
   120  			Name:      "total_originated_credited_amount",
   121  			Help:      "Amount of BZZ credited to peers (potential cost of the node) for originated traffic",
   122  		}),
   123  		OriginatedCreditEventsCount: prometheus.NewCounter(prometheus.CounterOpts{
   124  			Namespace: m.Namespace,
   125  			Subsystem: subsystem,
   126  			Name:      "originated_credit_events_count",
   127  			Help:      "Number of occurrences of BZZ credit events as originator towards peers",
   128  		}),
   129  		SettleErrorCount: prometheus.NewCounter(prometheus.CounterOpts{
   130  			Namespace: m.Namespace,
   131  			Subsystem: subsystem,
   132  			Name:      "settle_error_count",
   133  			Help:      "Number of errors occurring in settle method",
   134  		}),
   135  		PaymentErrorCount: prometheus.NewCounter(prometheus.CounterOpts{
   136  			Namespace: m.Namespace,
   137  			Subsystem: subsystem,
   138  			Name:      "payment_error_count",
   139  			Help:      "Number of errors occurring during payment op",
   140  		}),
   141  		PaymentAttemptCount: prometheus.NewCounter(prometheus.CounterOpts{
   142  			Namespace: m.Namespace,
   143  			Subsystem: subsystem,
   144  			Name:      "payment_attempt_count",
   145  			Help:      "Number of attempts of payment op",
   146  		}),
   147  		ErrRefreshmentBelowExpected: prometheus.NewCounter(prometheus.CounterOpts{
   148  			Namespace: m.Namespace,
   149  			Subsystem: subsystem,
   150  			Name:      "refreshment_below_expected",
   151  			Help:      "Number of times the peer received a refreshment that is below expected",
   152  		}),
   153  		ErrRefreshmentAboveExpected: prometheus.NewCounter(prometheus.CounterOpts{
   154  			Namespace: m.Namespace,
   155  			Subsystem: subsystem,
   156  			Name:      "refreshment_above_expected",
   157  			Help:      "Number of times the peer received a refreshment that is above expected",
   158  		}),
   159  		ErrTimeOutOfSyncAlleged: prometheus.NewCounter(prometheus.CounterOpts{
   160  			Namespace: m.Namespace,
   161  			Subsystem: subsystem,
   162  			Name:      "time_out_of_sync_alleged",
   163  			Help:      "Number of times the timestamps from peer were decreasing",
   164  		}),
   165  		ErrTimeOutOfSyncRecent: prometheus.NewCounter(prometheus.CounterOpts{
   166  			Namespace: m.Namespace,
   167  			Subsystem: subsystem,
   168  			Name:      "time_out_of_sync_recent",
   169  			Help:      "Number of times the timestamps from peer differed from our measurement by more than 2 seconds",
   170  		}),
   171  		ErrTimeOutOfSyncInterval: prometheus.NewCounter(prometheus.CounterOpts{
   172  			Namespace: m.Namespace,
   173  			Subsystem: subsystem,
   174  			Name:      "time_out_of_sync_interval",
   175  			Help:      "Number of times the time interval from peer differed from local interval by more than 3 seconds",
   176  		}),
   177  	}
   178  }
   179  
   180  // Metrics returns the prometheus Collector for the accounting service.
   181  func (a *Accounting) Metrics() []prometheus.Collector {
   182  	return m.PrometheusCollectorsFromFields(a.metrics)
   183  }