github.com/ethersphere/bee/v2@v2.2.0/pkg/pushsync/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 pushsync
     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  	TotalSent               prometheus.Counter
    14  	TotalReceived           prometheus.Counter
    15  	TotalHandlerErrors      prometheus.Counter
    16  	TotalRequests           prometheus.Counter
    17  	TotalSendAttempts       prometheus.Counter
    18  	TotalFailedSendAttempts prometheus.Counter
    19  	TotalOutgoing           prometheus.Counter
    20  	TotalOutgoingErrors     prometheus.Counter
    21  	InvalidStampErrors      prometheus.Counter
    22  	StampValidationTime     prometheus.HistogramVec
    23  	Forwarder               prometheus.Counter
    24  	Storer                  prometheus.Counter
    25  	TotalHandlerTime        prometheus.HistogramVec
    26  	PushToPeerTime          prometheus.HistogramVec
    27  
    28  	ReceiptDepth        *prometheus.CounterVec
    29  	ShallowReceiptDepth *prometheus.CounterVec
    30  	ShallowReceipt      prometheus.Counter
    31  }
    32  
    33  func newMetrics() metrics {
    34  	subsystem := "pushsync"
    35  
    36  	return metrics{
    37  		TotalSent: prometheus.NewCounter(prometheus.CounterOpts{
    38  			Namespace: m.Namespace,
    39  			Subsystem: subsystem,
    40  			Name:      "total_sent",
    41  			Help:      "Total chunks sent.",
    42  		}),
    43  		TotalReceived: prometheus.NewCounter(prometheus.CounterOpts{
    44  			Namespace: m.Namespace,
    45  			Subsystem: subsystem,
    46  			Name:      "total_received",
    47  			Help:      "Total chunks received.",
    48  		}),
    49  		TotalHandlerErrors: prometheus.NewCounter(prometheus.CounterOpts{
    50  			Namespace: m.Namespace,
    51  			Subsystem: subsystem,
    52  			Name:      "total_handler_errors",
    53  			Help:      "Total no of error occurred while handling an incoming delivery (either while storing or forwarding).",
    54  		}),
    55  		TotalRequests: prometheus.NewCounter(prometheus.CounterOpts{
    56  			Namespace: m.Namespace,
    57  			Subsystem: subsystem,
    58  			Name:      "total_requests",
    59  			Help:      "Total no of requests to push a chunk into the network (from origin nodes or not).",
    60  		}),
    61  		TotalSendAttempts: prometheus.NewCounter(prometheus.CounterOpts{
    62  			Namespace: m.Namespace,
    63  			Subsystem: subsystem,
    64  			Name:      "total_send_attempts",
    65  			Help:      "Total no of attempts to push chunk.",
    66  		}),
    67  		TotalFailedSendAttempts: prometheus.NewCounter(prometheus.CounterOpts{
    68  			Namespace: m.Namespace,
    69  			Subsystem: subsystem,
    70  			Name:      "total_failed_send_attempts",
    71  			Help:      "Total no of failed attempts to push chunk.",
    72  		}),
    73  		TotalOutgoing: prometheus.NewCounter(prometheus.CounterOpts{
    74  			Namespace: m.Namespace,
    75  			Subsystem: subsystem,
    76  			Name:      "total_outgoing",
    77  			Help:      "Total no of chunks requested to be synced (calls on exported PushChunkToClosest)",
    78  		}),
    79  		TotalOutgoingErrors: prometheus.NewCounter(prometheus.CounterOpts{
    80  			Namespace: m.Namespace,
    81  			Subsystem: subsystem,
    82  			Name:      "total_outgoing_errors",
    83  			Help:      "Total no of errors of entire operation to sync a chunk (multiple attempts included)",
    84  		}),
    85  		InvalidStampErrors: prometheus.NewCounter(prometheus.CounterOpts{
    86  			Namespace: m.Namespace,
    87  			Subsystem: subsystem,
    88  			Name:      "invalid_stamps",
    89  			Help:      "No of invalid stamp errors.",
    90  		}),
    91  		StampValidationTime: *prometheus.NewHistogramVec(prometheus.HistogramOpts{
    92  			Namespace: m.Namespace,
    93  			Subsystem: subsystem,
    94  			Name:      "stamp_validation_time",
    95  			Help:      "Time taken to validate stamps.",
    96  		}, []string{"status"}),
    97  		Forwarder: prometheus.NewCounter(prometheus.CounterOpts{
    98  			Namespace: m.Namespace,
    99  			Subsystem: subsystem,
   100  			Name:      "forwarder",
   101  			Help:      "No of times the peer is a forwarder node.",
   102  		}),
   103  		Storer: prometheus.NewCounter(prometheus.CounterOpts{
   104  			Namespace: m.Namespace,
   105  			Subsystem: subsystem,
   106  			Name:      "storer",
   107  			Help:      "No of times the peer is a storer node.",
   108  		}),
   109  		TotalHandlerTime: *prometheus.NewHistogramVec(
   110  			prometheus.HistogramOpts{
   111  				Namespace: m.Namespace,
   112  				Subsystem: subsystem,
   113  				Name:      "total_handler_time",
   114  				Help:      "Histogram for time taken for the handler.",
   115  			}, []string{"status"},
   116  		),
   117  		PushToPeerTime: *prometheus.NewHistogramVec(
   118  			prometheus.HistogramOpts{
   119  				Namespace: m.Namespace,
   120  				Subsystem: subsystem,
   121  				Name:      "push_peer_time",
   122  				Help:      "Histogram for time taken to push a chunk to a peer.",
   123  			}, []string{"status"},
   124  		),
   125  		ShallowReceiptDepth: prometheus.NewCounterVec(
   126  			prometheus.CounterOpts{
   127  				Namespace: m.Namespace,
   128  				Subsystem: subsystem,
   129  				Name:      "shallow_receipt_depth",
   130  				Help:      "Counter of shallow receipts received at different depths.",
   131  			},
   132  			[]string{"depth"},
   133  		),
   134  		ShallowReceipt: prometheus.NewCounter(prometheus.CounterOpts{
   135  			Namespace: m.Namespace,
   136  			Subsystem: subsystem,
   137  			Name:      "shallow_receipt",
   138  			Help:      "Total shallow receipts.",
   139  		}),
   140  		ReceiptDepth: prometheus.NewCounterVec(
   141  			prometheus.CounterOpts{
   142  				Namespace: m.Namespace,
   143  				Subsystem: subsystem,
   144  				Name:      "receipt_depth",
   145  				Help:      "Counter of receipts received at different depths.",
   146  			},
   147  			[]string{"depth"},
   148  		),
   149  	}
   150  }
   151  
   152  func (s *PushSync) Metrics() []prometheus.Collector {
   153  	return m.PrometheusCollectorsFromFields(s.metrics)
   154  }