github.com/ethersphere/bee/v2@v2.2.0/pkg/retrieval/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 retrieval
     6  
     7  import (
     8  	"github.com/prometheus/client_golang/prometheus"
     9  
    10  	m "github.com/ethersphere/bee/v2/pkg/metrics"
    11  )
    12  
    13  type metrics struct {
    14  	// all metrics fields must be exported
    15  	// to be able to return them by Metrics()
    16  	// using reflection
    17  
    18  	RequestCounter        prometheus.Counter
    19  	RequestSuccessCounter prometheus.Counter
    20  	RequestFailureCounter prometheus.Counter
    21  	RequestDurationTime   prometheus.Histogram
    22  	RequestAttempts       prometheus.Histogram
    23  	PeerRequestCounter    prometheus.Counter
    24  	TotalRetrieved        prometheus.Counter
    25  	InvalidChunkRetrieved prometheus.Counter
    26  	ChunkPrice            prometheus.Summary
    27  	TotalErrors           prometheus.Counter
    28  	ChunkRetrieveTime     prometheus.Histogram
    29  }
    30  
    31  func newMetrics() metrics {
    32  	subsystem := "retrieval"
    33  
    34  	return metrics{
    35  		RequestCounter: prometheus.NewCounter(prometheus.CounterOpts{
    36  			Namespace: m.Namespace,
    37  			Subsystem: subsystem,
    38  			Name:      "request_count",
    39  			Help:      "Number of requests to retrieve chunks.",
    40  		}),
    41  		RequestSuccessCounter: prometheus.NewCounter(prometheus.CounterOpts{
    42  			Namespace: m.Namespace,
    43  			Subsystem: subsystem,
    44  			Name:      "request_success_count",
    45  			Help:      "Number of requests which succeeded to retrieve chunk.",
    46  		}),
    47  		RequestFailureCounter: prometheus.NewCounter(prometheus.CounterOpts{
    48  			Namespace: m.Namespace,
    49  			Subsystem: subsystem,
    50  			Name:      "request_failure_count",
    51  			Help:      "Number of requests which failed to retrieve chunk.",
    52  		}),
    53  		RequestDurationTime: prometheus.NewHistogram(prometheus.HistogramOpts{
    54  			Namespace: m.Namespace,
    55  			Subsystem: subsystem,
    56  			Name:      "request_duration_time",
    57  			Help:      "Histogram for time taken to complete retrieval request",
    58  		}),
    59  		RequestAttempts: prometheus.NewHistogram(prometheus.HistogramOpts{
    60  			Namespace: m.Namespace,
    61  			Subsystem: subsystem,
    62  			Name:      "request_attempts",
    63  			Help:      "Histogram for total retrieval attempts pre each request.",
    64  		}),
    65  		PeerRequestCounter: prometheus.NewCounter(prometheus.CounterOpts{
    66  			Namespace: m.Namespace,
    67  			Subsystem: subsystem,
    68  			Name:      "peer_request_count",
    69  			Help:      "Number of request to single peer.",
    70  		}),
    71  		TotalRetrieved: prometheus.NewCounter(prometheus.CounterOpts{
    72  			Namespace: m.Namespace,
    73  			Subsystem: subsystem,
    74  			Name:      "total_retrieved",
    75  			Help:      "Total chunks retrieved.",
    76  		}),
    77  		InvalidChunkRetrieved: prometheus.NewCounter(prometheus.CounterOpts{
    78  			Namespace: m.Namespace,
    79  			Subsystem: subsystem,
    80  			Name:      "invalid_chunk_retrieved",
    81  			Help:      "Invalid chunk retrieved from peer.",
    82  		}),
    83  		ChunkPrice: prometheus.NewSummary(prometheus.SummaryOpts{
    84  			Namespace: m.Namespace,
    85  			Subsystem: subsystem,
    86  			Name:      "chunk_price",
    87  			Help:      "The price of the chunk that was paid.",
    88  		}),
    89  		TotalErrors: prometheus.NewCounter(prometheus.CounterOpts{
    90  			Namespace: m.Namespace,
    91  			Subsystem: subsystem,
    92  			Name:      "total_errors",
    93  			Help:      "Total number of errors while retrieving chunk.",
    94  		}),
    95  		ChunkRetrieveTime: prometheus.NewHistogram(prometheus.HistogramOpts{
    96  			Namespace: m.Namespace,
    97  			Subsystem: subsystem,
    98  			Name:      "retrieve_chunk_time",
    99  			Help:      "Histogram for time taken to retrieve a chunk.",
   100  		},
   101  		),
   102  	}
   103  }
   104  
   105  func (s *Service) Metrics() []prometheus.Collector {
   106  	return m.PrometheusCollectorsFromFields(s.metrics)
   107  }