github.com/ethersphere/bee/v2@v2.2.0/pkg/settlement/pseudosettle/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 pseudosettle 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 // all metrics fields must be exported 14 // to be able to return them by Metrics() 15 // using reflection 16 TotalReceivedPseudoSettlements prometheus.Counter 17 TotalSentPseudoSettlements prometheus.Counter 18 ReceivedPseudoSettlements prometheus.Counter 19 SentPseudoSettlements prometheus.Counter 20 ReceivedPseudoSettlementsErrors prometheus.Counter 21 SentPseudoSettlementsErrors prometheus.Counter 22 } 23 24 func newMetrics() metrics { 25 subsystem := "pseudosettle" 26 27 return metrics{ 28 TotalReceivedPseudoSettlements: prometheus.NewCounter(prometheus.CounterOpts{ 29 Namespace: m.Namespace, 30 Subsystem: subsystem, 31 Name: "total_received_pseudosettlements", 32 Help: "Amount of time settlements received from peers (income of the node)", 33 }), 34 TotalSentPseudoSettlements: prometheus.NewCounter(prometheus.CounterOpts{ 35 Namespace: m.Namespace, 36 Subsystem: subsystem, 37 Name: "total_sent_pseudosettlements", 38 Help: "Amount of of time settlements sent to peers (costs paid by the node)", 39 }), 40 ReceivedPseudoSettlements: prometheus.NewCounter(prometheus.CounterOpts{ 41 Namespace: m.Namespace, 42 Subsystem: subsystem, 43 Name: "received_pseudosettlements", 44 Help: "Number of time settlements received from peers", 45 }), 46 SentPseudoSettlements: prometheus.NewCounter(prometheus.CounterOpts{ 47 Namespace: m.Namespace, 48 Subsystem: subsystem, 49 Name: "sent_pseudosettlements", 50 Help: "Number of time settlements sent to peers", 51 }), 52 ReceivedPseudoSettlementsErrors: prometheus.NewCounter(prometheus.CounterOpts{ 53 Namespace: m.Namespace, 54 Subsystem: subsystem, 55 Name: "received_pseudosettlements_errors", 56 Help: "Errors of time settlements received from peers", 57 }), 58 SentPseudoSettlementsErrors: prometheus.NewCounter(prometheus.CounterOpts{ 59 Namespace: m.Namespace, 60 Subsystem: subsystem, 61 Name: "sent_pseudosettlements_errorss", 62 Help: "Errors of time settlements sent to peers", 63 }), 64 } 65 } 66 67 func (s *Service) Metrics() []prometheus.Collector { 68 return m.PrometheusCollectorsFromFields(s.metrics) 69 }