github.com/ethersphere/bee/v2@v2.2.0/pkg/topology/lightnode/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 lightnode
     6  
     7  import (
     8  	m "github.com/ethersphere/bee/v2/pkg/metrics"
     9  	"github.com/prometheus/client_golang/prometheus"
    10  )
    11  
    12  // metrics groups lightnode related prometheus counters.
    13  type metrics struct {
    14  	CurrentlyConnectedPeers    prometheus.Gauge
    15  	CurrentlyDisconnectedPeers prometheus.Gauge
    16  }
    17  
    18  // newMetrics is a convenient constructor for creating new metrics.
    19  func newMetrics() metrics {
    20  	const subsystem = "lightnode"
    21  
    22  	return metrics{
    23  		CurrentlyConnectedPeers: prometheus.NewGauge(prometheus.GaugeOpts{
    24  			Namespace: m.Namespace,
    25  			Subsystem: subsystem,
    26  			Name:      "currently_connected_peers",
    27  			Help:      "Number of currently connected peers.",
    28  		}),
    29  		CurrentlyDisconnectedPeers: prometheus.NewGauge(prometheus.GaugeOpts{
    30  			Namespace: m.Namespace,
    31  			Subsystem: subsystem,
    32  			Name:      "currently_disconnected_peers",
    33  			Help:      "Number of currently disconnected peers.",
    34  		})}
    35  }
    36  
    37  // Metrics returns set of prometheus collectors.
    38  func (c *Container) Metrics() []prometheus.Collector {
    39  	return m.PrometheusCollectorsFromFields(c.metrics)
    40  }