github.com/ethersphere/bee/v2@v2.2.0/pkg/topology/kademlia/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 kademlia 6 7 import ( 8 m "github.com/ethersphere/bee/v2/pkg/metrics" 9 "github.com/prometheus/client_golang/prometheus" 10 ) 11 12 // metrics groups kademlia related prometheus counters. 13 type metrics struct { 14 PickCalls prometheus.Counter 15 PickCallsFalse prometheus.Counter 16 CurrentDepth prometheus.Gauge 17 CurrentStorageDepth prometheus.Gauge 18 CurrentlyKnownPeers prometheus.Gauge 19 CurrentlyConnectedPeers prometheus.Gauge 20 InternalMetricsFlushTime prometheus.Histogram 21 InternalMetricsFlushTotalErrors prometheus.Counter 22 TotalBeforeExpireWaits prometheus.Counter 23 TotalInboundConnections prometheus.Counter 24 TotalInboundDisconnections prometheus.Counter 25 TotalOutboundConnections prometheus.Counter 26 TotalOutboundConnectionAttempts prometheus.Counter 27 TotalOutboundConnectionFailedAttempts prometheus.Counter 28 TotalBootNodesConnectionAttempts prometheus.Counter 29 StartAddAddressBookOverlaysTime prometheus.Histogram 30 PeerLatencyEWMA prometheus.Histogram 31 Blocklist prometheus.Counter 32 ReachabilityStatus *prometheus.GaugeVec 33 PeersReachabilityStatus *prometheus.GaugeVec 34 } 35 36 // newMetrics is a convenient constructor for creating new metrics. 37 func newMetrics() metrics { 38 const subsystem = "kademlia" 39 40 return metrics{ 41 PickCalls: prometheus.NewCounter(prometheus.CounterOpts{ 42 Namespace: m.Namespace, 43 Subsystem: subsystem, 44 Name: "pick_calls", 45 Help: "The number of pick method call made.", 46 }), 47 PickCallsFalse: prometheus.NewCounter(prometheus.CounterOpts{ 48 Namespace: m.Namespace, 49 Subsystem: subsystem, 50 Name: "pick_calls_false", 51 Help: "The number of pick method call made which returned false.", 52 }), 53 CurrentDepth: prometheus.NewGauge(prometheus.GaugeOpts{ 54 Namespace: m.Namespace, 55 Subsystem: subsystem, 56 Name: "current_depth", 57 Help: "The current value of depth.", 58 }), 59 CurrentStorageDepth: prometheus.NewGauge(prometheus.GaugeOpts{ 60 Namespace: m.Namespace, 61 Subsystem: subsystem, 62 Name: "current_storage_depth", 63 Help: "The current value of storage depth.", 64 }), 65 CurrentlyKnownPeers: prometheus.NewGauge(prometheus.GaugeOpts{ 66 Namespace: m.Namespace, 67 Subsystem: subsystem, 68 Name: "currently_known_peers", 69 Help: "Number of currently known peers.", 70 }), 71 CurrentlyConnectedPeers: prometheus.NewGauge(prometheus.GaugeOpts{ 72 Namespace: m.Namespace, 73 Subsystem: subsystem, 74 Name: "currently_connected_peers", 75 Help: "Number of currently connected peers.", 76 }), 77 InternalMetricsFlushTime: prometheus.NewHistogram(prometheus.HistogramOpts{ 78 Namespace: m.Namespace, 79 Subsystem: subsystem, 80 Name: "internal_metrics_flush_time", 81 Help: "The time spent flushing the internal metrics about peers to the state-store.", 82 }), 83 InternalMetricsFlushTotalErrors: prometheus.NewCounter(prometheus.CounterOpts{ 84 Namespace: m.Namespace, 85 Subsystem: subsystem, 86 Name: "internal_metrics_flush_total_errors", 87 Help: "Number of total errors occurred during flushing the internal metrics to the state-store.", 88 }), 89 TotalBeforeExpireWaits: prometheus.NewCounter(prometheus.CounterOpts{ 90 Namespace: m.Namespace, 91 Subsystem: subsystem, 92 Name: "total_before_expire_waits", 93 Help: "Total before expire waits made.", 94 }), 95 TotalInboundConnections: prometheus.NewCounter(prometheus.CounterOpts{ 96 Namespace: m.Namespace, 97 Subsystem: subsystem, 98 Name: "total_inbound_connections", 99 Help: "Total inbound connections made.", 100 }), 101 TotalInboundDisconnections: prometheus.NewCounter(prometheus.CounterOpts{ 102 Namespace: m.Namespace, 103 Subsystem: subsystem, 104 Name: "total_inbound_disconnections", 105 Help: "Total inbound disconnections made.", 106 }), 107 TotalOutboundConnections: prometheus.NewCounter(prometheus.CounterOpts{ 108 Namespace: m.Namespace, 109 Subsystem: subsystem, 110 Name: "total_outbound_connections", 111 Help: "Total outbound connections made.", 112 }), 113 TotalOutboundConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{ 114 Namespace: m.Namespace, 115 Subsystem: subsystem, 116 Name: "total_outbound_connection_attempts", 117 Help: "Total outbound connection attempts made.", 118 }), 119 TotalOutboundConnectionFailedAttempts: prometheus.NewCounter(prometheus.CounterOpts{ 120 Namespace: m.Namespace, 121 Subsystem: subsystem, 122 Name: "total_outbound_connection_failed_attempts", 123 Help: "Total outbound connection failed attempts made.", 124 }), 125 TotalBootNodesConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{ 126 Namespace: m.Namespace, 127 Subsystem: subsystem, 128 Name: "total_bootnodes_connection_attempts", 129 Help: "Total boot-nodes connection attempts made.", 130 }), 131 StartAddAddressBookOverlaysTime: prometheus.NewHistogram(prometheus.HistogramOpts{ 132 Namespace: m.Namespace, 133 Subsystem: subsystem, 134 Name: "start_add_addressbook_overlays_time", 135 Help: "The time spent adding overlays peers from addressbook on kademlia start.", 136 }), 137 PeerLatencyEWMA: prometheus.NewHistogram(prometheus.HistogramOpts{ 138 Namespace: m.Namespace, 139 Subsystem: subsystem, 140 Name: "peer_latency_ewma", 141 Help: "Peer latency EWMA value distribution.", 142 }), 143 Blocklist: prometheus.NewCounter(prometheus.CounterOpts{ 144 Namespace: m.Namespace, 145 Subsystem: subsystem, 146 Name: "blocklist", 147 Help: "The number of times peers have been blocklisted.", 148 }), 149 ReachabilityStatus: prometheus.NewGaugeVec( 150 prometheus.GaugeOpts{ 151 Namespace: m.Namespace, 152 Subsystem: subsystem, 153 Name: "reachability_status", 154 Help: "The reachability status of the node.", 155 }, 156 []string{"reachability_status"}, 157 ), 158 PeersReachabilityStatus: prometheus.NewGaugeVec( 159 prometheus.GaugeOpts{ 160 Namespace: m.Namespace, 161 Subsystem: subsystem, 162 Name: "peers_reachability_status", 163 Help: "The reachability status of peers.", 164 }, 165 []string{"peers_reachability_status"}, 166 ), 167 } 168 } 169 170 // Metrics returns set of prometheus collectors. 171 func (k *Kad) Metrics() []prometheus.Collector { 172 return m.PrometheusCollectorsFromFields(k.metrics) 173 }