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

     1  // Copyright 2022 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 storageincentives
     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  	// phase gauge and counter
    14  	CurrentPhase            prometheus.Gauge
    15  	RevealPhase             prometheus.Counter
    16  	CommitPhase             prometheus.Counter
    17  	ClaimPhase              prometheus.Counter
    18  	Winner                  prometheus.Counter
    19  	NeighborhoodSelected    prometheus.Counter
    20  	SampleDuration          prometheus.Gauge
    21  	Round                   prometheus.Gauge
    22  	InsufficientFundsToPlay prometheus.Counter
    23  
    24  	// total calls to chain backend
    25  	BackendCalls  prometheus.Counter
    26  	BackendErrors prometheus.Counter
    27  
    28  	// metrics for err processing
    29  	ErrReveal         prometheus.Counter
    30  	ErrCommit         prometheus.Counter
    31  	ErrClaim          prometheus.Counter
    32  	ErrWinner         prometheus.Counter
    33  	ErrCheckIsPlaying prometheus.Counter
    34  }
    35  
    36  func newMetrics() metrics {
    37  	subsystem := "storageincentives"
    38  
    39  	return metrics{
    40  		CurrentPhase: prometheus.NewGauge(prometheus.GaugeOpts{
    41  			Namespace: m.Namespace,
    42  			Subsystem: subsystem,
    43  			Name:      "current_phase",
    44  			Help:      "Enum value of the current phase.",
    45  		}),
    46  		RevealPhase: prometheus.NewCounter(prometheus.CounterOpts{
    47  			Namespace: m.Namespace,
    48  			Subsystem: subsystem,
    49  			Name:      "reveal_phases",
    50  			Help:      "Count of reveal phases entered.",
    51  		}),
    52  		CommitPhase: prometheus.NewCounter(prometheus.CounterOpts{
    53  			Namespace: m.Namespace,
    54  			Subsystem: subsystem,
    55  			Name:      "commit_phases",
    56  			Help:      "Count of commit phases entered.",
    57  		}),
    58  		InsufficientFundsToPlay: prometheus.NewCounter(prometheus.CounterOpts{
    59  			Namespace: m.Namespace,
    60  			Subsystem: subsystem,
    61  			Name:      "insufficient_funds_to_play",
    62  			Help:      "Count of games skipped due to insufficient balance to participate.",
    63  		}),
    64  		ClaimPhase: prometheus.NewCounter(prometheus.CounterOpts{
    65  			Namespace: m.Namespace,
    66  			Subsystem: subsystem,
    67  			Name:      "claim_phases",
    68  			Help:      "Count of claim phases entered.",
    69  		}),
    70  		Winner: prometheus.NewCounter(prometheus.CounterOpts{
    71  			Namespace: m.Namespace,
    72  			Subsystem: subsystem,
    73  			Name:      "winner",
    74  			Help:      "Count of won rounds.",
    75  		}),
    76  		NeighborhoodSelected: prometheus.NewCounter(prometheus.CounterOpts{
    77  			Namespace: m.Namespace,
    78  			Subsystem: subsystem,
    79  			Name:      "neighborhood_selected",
    80  			Help:      "Count of the neighborhood being selected.",
    81  		}),
    82  		SampleDuration: prometheus.NewGauge(prometheus.GaugeOpts{
    83  			Namespace: m.Namespace,
    84  			Subsystem: subsystem,
    85  			Name:      "reserve_sample_duration",
    86  			Help:      "Time taken to produce a reserve sample.",
    87  		}),
    88  		Round: prometheus.NewGauge(prometheus.GaugeOpts{
    89  			Namespace: m.Namespace,
    90  			Subsystem: subsystem,
    91  			Name:      "round",
    92  			Help:      "Current round calculated from the block height.",
    93  		}),
    94  
    95  		// total call
    96  		BackendCalls: prometheus.NewCounter(prometheus.CounterOpts{
    97  			Namespace: m.Namespace,
    98  			Subsystem: subsystem,
    99  			Name:      "backend_calls",
   100  			Help:      "total chain backend calls",
   101  		}),
   102  		BackendErrors: prometheus.NewCounter(prometheus.CounterOpts{
   103  			Namespace: m.Namespace,
   104  			Subsystem: subsystem,
   105  			Name:      "backend_errors",
   106  			Help:      "total chain backend errors",
   107  		}),
   108  
   109  		// phase errors
   110  		ErrReveal: prometheus.NewCounter(prometheus.CounterOpts{
   111  			Namespace: m.Namespace,
   112  			Subsystem: subsystem,
   113  			Name:      "reveal_phase_errors",
   114  			Help:      "total reveal phase errors while processing",
   115  		}),
   116  		ErrCommit: prometheus.NewCounter(prometheus.CounterOpts{
   117  			Namespace: m.Namespace,
   118  			Subsystem: subsystem,
   119  			Name:      "commit_phase_errors",
   120  			Help:      "total commit phase errors while processing",
   121  		}),
   122  		ErrClaim: prometheus.NewCounter(prometheus.CounterOpts{
   123  			Namespace: m.Namespace,
   124  			Subsystem: subsystem,
   125  			Name:      "claim_phase_errors",
   126  			Help:      "total claim phase errors while processing",
   127  		}),
   128  		ErrWinner: prometheus.NewCounter(prometheus.CounterOpts{
   129  			Namespace: m.Namespace,
   130  			Subsystem: subsystem,
   131  			Name:      "win_phase_errors",
   132  			Help:      "total win phase while processing",
   133  		}),
   134  		ErrCheckIsPlaying: prometheus.NewCounter(prometheus.CounterOpts{
   135  			Namespace: m.Namespace,
   136  			Subsystem: subsystem,
   137  			Name:      "is_playing_errors",
   138  			Help:      "total neighborhood selected errors while processing",
   139  		}),
   140  	}
   141  }
   142  
   143  // TODO: register metric
   144  func (a *Agent) Metrics() []prometheus.Collector {
   145  	return m.PrometheusCollectorsFromFields(a.metrics)
   146  }