github.com/ethersphere/bee/v2@v2.2.0/pkg/p2p/libp2p/internal/handshake/metrics.go (about)

     1  // Copyright 2021 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 handshake
     6  
     7  import (
     8  	m "github.com/ethersphere/bee/v2/pkg/metrics"
     9  	"github.com/prometheus/client_golang/prometheus"
    10  )
    11  
    12  // metrics groups handshake related prometheus counters.
    13  type metrics struct {
    14  	SynRx          prometheus.Counter
    15  	SynRxFailed    prometheus.Counter
    16  	SynAckTx       prometheus.Counter
    17  	SynAckTxFailed prometheus.Counter
    18  	AckRx          prometheus.Counter
    19  	AckRxFailed    prometheus.Counter
    20  }
    21  
    22  // newMetrics is a convenient constructor for creating new metrics.
    23  func newMetrics() metrics {
    24  	const subsystem = "handshake"
    25  
    26  	return metrics{
    27  		SynRx: prometheus.NewCounter(prometheus.CounterOpts{
    28  			Namespace: m.Namespace,
    29  			Subsystem: subsystem,
    30  			Name:      "syn_rx",
    31  			Help:      "The number of syn messages that were successfully read.",
    32  		}),
    33  		SynRxFailed: prometheus.NewCounter(prometheus.CounterOpts{
    34  			Namespace: m.Namespace,
    35  			Subsystem: subsystem,
    36  			Name:      "syn_rx_failed",
    37  			Help:      "The number of syn messages that were unsuccessfully read.",
    38  		}),
    39  		SynAckTx: prometheus.NewCounter(prometheus.CounterOpts{
    40  			Namespace: m.Namespace,
    41  			Subsystem: subsystem,
    42  			Name:      "syn_ack_tx",
    43  			Help:      "The number of syn-ack messages that were successfully written.",
    44  		}),
    45  		SynAckTxFailed: prometheus.NewCounter(prometheus.CounterOpts{
    46  			Namespace: m.Namespace,
    47  			Subsystem: subsystem,
    48  			Name:      "syn_ack_tx_failed",
    49  			Help:      "The number of syn-ack messages that were unsuccessfully written.",
    50  		}),
    51  		AckRx: prometheus.NewCounter(prometheus.CounterOpts{
    52  			Namespace: m.Namespace,
    53  			Subsystem: subsystem,
    54  			Name:      "ack_rx",
    55  			Help:      "The number of ack messages that were successfully read.",
    56  		}),
    57  		AckRxFailed: prometheus.NewCounter(prometheus.CounterOpts{
    58  			Namespace: m.Namespace,
    59  			Subsystem: subsystem,
    60  			Name:      "ack_rx_failed",
    61  			Help:      "The number of ack messages that were unsuccessfully read.",
    62  		}),
    63  	}
    64  }
    65  
    66  // Metrics returns set of prometheus collectors.
    67  func (s *Service) Metrics() []prometheus.Collector {
    68  	return m.PrometheusCollectorsFromFields(s.metrics)
    69  }