github.com/ethersphere/bee/v2@v2.2.0/pkg/hive/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 hive 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 BroadcastPeers prometheus.Counter 14 BroadcastPeersPeers prometheus.Counter 15 BroadcastPeersSends prometheus.Counter 16 17 PeersHandler prometheus.Counter 18 PeersHandlerPeers prometheus.Counter 19 UnreachablePeers prometheus.Counter 20 21 PingTime prometheus.Histogram 22 PingFailureTime prometheus.Histogram 23 24 PeerConnectAttempts prometheus.Counter 25 PeerUnderlayErr prometheus.Counter 26 StorePeerErr prometheus.Counter 27 ReachablePeers prometheus.Counter 28 } 29 30 func newMetrics() metrics { 31 subsystem := "hive" 32 33 return metrics{ 34 BroadcastPeers: prometheus.NewCounter(prometheus.CounterOpts{ 35 Namespace: m.Namespace, 36 Subsystem: subsystem, 37 Name: "broadcast_peers_count", 38 Help: "Number of calls to broadcast peers.", 39 }), 40 BroadcastPeersPeers: prometheus.NewCounter(prometheus.CounterOpts{ 41 Namespace: m.Namespace, 42 Subsystem: subsystem, 43 Name: "broadcast_peers_peer_count", 44 Help: "Number of peers to be sent.", 45 }), 46 BroadcastPeersSends: prometheus.NewCounter(prometheus.CounterOpts{ 47 Namespace: m.Namespace, 48 Subsystem: subsystem, 49 Name: "broadcast_peers_message_count", 50 Help: "Number of individual peer gossip messages sent.", 51 }), 52 PeersHandler: prometheus.NewCounter(prometheus.CounterOpts{ 53 Namespace: m.Namespace, 54 Subsystem: subsystem, 55 Name: "peers_handler_count", 56 Help: "Number of peer messages received.", 57 }), 58 PeersHandlerPeers: prometheus.NewCounter(prometheus.CounterOpts{ 59 Namespace: m.Namespace, 60 Subsystem: subsystem, 61 Name: "peers_handler_peers_count", 62 Help: "Number of peers received in peer messages.", 63 }), 64 UnreachablePeers: prometheus.NewCounter(prometheus.CounterOpts{ 65 Namespace: m.Namespace, 66 Subsystem: subsystem, 67 Name: "unreachable_peers_count", 68 Help: "Number of peers that are unreachable.", 69 }), 70 PingTime: prometheus.NewHistogram(prometheus.HistogramOpts{ 71 Namespace: m.Namespace, 72 Subsystem: subsystem, 73 Name: "ping_time", 74 Help: "The time spent for pings.", 75 }), 76 PingFailureTime: prometheus.NewHistogram(prometheus.HistogramOpts{ 77 Namespace: m.Namespace, 78 Subsystem: subsystem, 79 Name: "fail_ping_time", 80 Help: "The time spent for unsuccessful pings.", 81 }), 82 PeerConnectAttempts: prometheus.NewCounter(prometheus.CounterOpts{ 83 Namespace: m.Namespace, 84 Subsystem: subsystem, 85 Name: "peer_attempt_count", 86 Help: "Number of attempts made to check peer reachability.", 87 }), 88 PeerUnderlayErr: prometheus.NewCounter(prometheus.CounterOpts{ 89 Namespace: m.Namespace, 90 Subsystem: subsystem, 91 Name: "peer_underlay_err_count", 92 Help: "Number of errors extracting peer underlay.", 93 }), 94 StorePeerErr: prometheus.NewCounter(prometheus.CounterOpts{ 95 Namespace: m.Namespace, 96 Subsystem: subsystem, 97 Name: "store_peer_err_count", 98 Help: "Number of peers that could not be stored.", 99 }), 100 ReachablePeers: prometheus.NewCounter(prometheus.CounterOpts{ 101 Namespace: m.Namespace, 102 Subsystem: subsystem, 103 Name: "reachable_peers_count", 104 Help: "Number of peers that are reachable.", 105 }), 106 } 107 } 108 109 func (s *Service) Metrics() []prometheus.Collector { 110 return m.PrometheusCollectorsFromFields(s.metrics) 111 }