github.com/ethersphere/bee/v2@v2.2.0/pkg/pusher/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 pusher
     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  	TotalToPush      prometheus.Counter
    14  	TotalSynced      prometheus.Counter
    15  	TotalErrors      prometheus.Counter
    16  	MarkAndSweepTime prometheus.Histogram
    17  	SyncTime         prometheus.Histogram
    18  	ErrorTime        prometheus.Histogram
    19  }
    20  
    21  func newMetrics() metrics {
    22  	subsystem := "pusher"
    23  
    24  	return metrics{
    25  		TotalToPush: prometheus.NewCounter(prometheus.CounterOpts{
    26  			Namespace: m.Namespace,
    27  			Subsystem: subsystem,
    28  			Name:      "total_to_push",
    29  			Help:      "Total chunks to push (chunks may be repeated).",
    30  		}),
    31  		TotalSynced: prometheus.NewCounter(prometheus.CounterOpts{
    32  			Namespace: m.Namespace,
    33  			Subsystem: subsystem,
    34  			Name:      "total_synced",
    35  			Help:      "Total chunks synced successfully with valid receipts.",
    36  		}),
    37  		TotalErrors: prometheus.NewCounter(prometheus.CounterOpts{
    38  			Namespace: m.Namespace,
    39  			Subsystem: subsystem,
    40  			Name:      "total_errors",
    41  			Help:      "Total errors encountered.",
    42  		}),
    43  		SyncTime: prometheus.NewHistogram(prometheus.HistogramOpts{
    44  			Namespace: m.Namespace,
    45  			Subsystem: subsystem,
    46  			Name:      "sync_time",
    47  			Help:      "Histogram of time spent to sync a chunk.",
    48  			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
    49  		}),
    50  		ErrorTime: prometheus.NewHistogram(prometheus.HistogramOpts{
    51  			Namespace: m.Namespace,
    52  			Subsystem: subsystem,
    53  			Name:      "error_time",
    54  			Help:      "Histogram of time spent before giving up on syncing a chunk.",
    55  			Buckets:   []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 60},
    56  		}),
    57  	}
    58  }
    59  
    60  func (s *Service) Metrics() []prometheus.Collector {
    61  	return m.PrometheusCollectorsFromFields(s.metrics)
    62  }