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

     1  // Copyright 2023 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 salud
     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  	AvgDur                prometheus.Gauge
    14  	PDur                  prometheus.Gauge
    15  	PConns                prometheus.Gauge
    16  	NetworkRadius         prometheus.Gauge
    17  	NeighborhoodRadius    prometheus.Gauge
    18  	Commitment            prometheus.Gauge
    19  	ReserveSizePercentErr prometheus.Gauge
    20  	Healthy               prometheus.Counter
    21  	Unhealthy             prometheus.Counter
    22  }
    23  
    24  func newMetrics() metrics {
    25  	subsystem := "salud"
    26  
    27  	return metrics{
    28  		AvgDur: prometheus.NewGauge(prometheus.GaugeOpts{
    29  			Namespace: m.Namespace,
    30  			Subsystem: subsystem,
    31  			Name:      "dur",
    32  			Help:      "Average duration for snapshot response.",
    33  		}),
    34  		PDur: prometheus.NewGauge(prometheus.GaugeOpts{
    35  			Namespace: m.Namespace,
    36  			Subsystem: subsystem,
    37  			Name:      "pdur",
    38  			Help:      "Percentile of durations for snapshot response.",
    39  		}),
    40  		PConns: prometheus.NewGauge(prometheus.GaugeOpts{
    41  			Namespace: m.Namespace,
    42  			Subsystem: subsystem,
    43  			Name:      "pconns",
    44  			Help:      "Percentile of connections counts.",
    45  		}),
    46  		NetworkRadius: prometheus.NewGauge(prometheus.GaugeOpts{
    47  			Namespace: m.Namespace,
    48  			Subsystem: subsystem,
    49  			Name:      "network_radius",
    50  			Help:      "Most common radius across the connected peers.",
    51  		}),
    52  		NeighborhoodRadius: prometheus.NewGauge(prometheus.GaugeOpts{
    53  			Namespace: m.Namespace,
    54  			Subsystem: subsystem,
    55  			Name:      "neighborhood_radius",
    56  			Help:      "Most common radius across the connected peers.",
    57  		}),
    58  		Healthy: prometheus.NewCounter(prometheus.CounterOpts{
    59  			Namespace: m.Namespace,
    60  			Subsystem: subsystem,
    61  			Name:      "healthy",
    62  			Help:      "Count of healthy peers.",
    63  		}),
    64  		Unhealthy: prometheus.NewCounter(prometheus.CounterOpts{
    65  			Namespace: m.Namespace,
    66  			Subsystem: subsystem,
    67  			Name:      "unhealthy",
    68  			Help:      "Count of unhealthy peers.",
    69  		}),
    70  		Commitment: prometheus.NewGauge(prometheus.GaugeOpts{
    71  			Namespace: m.Namespace,
    72  			Subsystem: subsystem,
    73  			Name:      "batch_commitment",
    74  			Help:      "Most common batch commitment.",
    75  		}),
    76  		ReserveSizePercentErr: prometheus.NewGauge(prometheus.GaugeOpts{
    77  			Namespace: m.Namespace,
    78  			Subsystem: subsystem,
    79  			Name:      "reserve_size_percentage_err",
    80  			Help:      "Percentage error of the reservesize relative to the network average.",
    81  		}),
    82  	}
    83  }
    84  
    85  func (s *service) Metrics() []prometheus.Collector {
    86  	return m.PrometheusCollectorsFromFields(s.metrics)
    87  }