github.com/ethersphere/bee/v2@v2.2.0/pkg/shed/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 shed 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 PutCounter prometheus.Counter 17 PutFailCounter prometheus.Counter 18 GetCounter prometheus.Counter 19 GetFailCounter prometheus.Counter 20 GetNotFoundCounter prometheus.Counter 21 HasCounter prometheus.Counter 22 HasFailCounter prometheus.Counter 23 DeleteCounter prometheus.Counter 24 DeleteFailCounter prometheus.Counter 25 IteratorCounter prometheus.Counter 26 WriteBatchCounter prometheus.Counter 27 WriteBatchFailCounter prometheus.Counter 28 } 29 30 func newMetrics() metrics { 31 subsystem := "shed" 32 33 return metrics{ 34 PutCounter: prometheus.NewCounter(prometheus.CounterOpts{ 35 Namespace: m.Namespace, 36 Subsystem: subsystem, 37 Name: "put_count", 38 Help: "Number of times the PUT operation is done.", 39 }), 40 PutFailCounter: prometheus.NewCounter(prometheus.CounterOpts{ 41 Namespace: m.Namespace, 42 Subsystem: subsystem, 43 Name: "put_fail_count", 44 Help: "Number of times the PUT operation failed.", 45 }), 46 GetCounter: prometheus.NewCounter(prometheus.CounterOpts{ 47 Namespace: m.Namespace, 48 Subsystem: subsystem, 49 Name: "get_count", 50 Help: "Number of times the GET operation is done.", 51 }), 52 GetNotFoundCounter: prometheus.NewCounter(prometheus.CounterOpts{ 53 Namespace: m.Namespace, 54 Subsystem: subsystem, 55 Name: "get_not_found_count", 56 Help: "Number of times the GET operation could not find key.", 57 }), 58 GetFailCounter: prometheus.NewCounter(prometheus.CounterOpts{ 59 Namespace: m.Namespace, 60 Subsystem: subsystem, 61 Name: "get_fail_count", 62 Help: "Number of times the GET operation is failed.", 63 }), 64 HasCounter: prometheus.NewCounter(prometheus.CounterOpts{ 65 Namespace: m.Namespace, 66 Subsystem: subsystem, 67 Name: "has_count", 68 Help: "Number of times the HAS operation is done.", 69 }), 70 HasFailCounter: prometheus.NewCounter(prometheus.CounterOpts{ 71 Namespace: m.Namespace, 72 Subsystem: subsystem, 73 Name: "has_fail_count", 74 Help: "Number of times the HAS operation failed.", 75 }), 76 DeleteCounter: prometheus.NewCounter(prometheus.CounterOpts{ 77 Namespace: m.Namespace, 78 Subsystem: subsystem, 79 Name: "delete_count", 80 Help: "Number of times the DELETE operation is done.", 81 }), 82 DeleteFailCounter: prometheus.NewCounter(prometheus.CounterOpts{ 83 Namespace: m.Namespace, 84 Subsystem: subsystem, 85 Name: "delete_fail_count", 86 Help: "Number of times the DELETE operation failed.", 87 }), 88 IteratorCounter: prometheus.NewCounter(prometheus.CounterOpts{ 89 Namespace: m.Namespace, 90 Subsystem: subsystem, 91 Name: "iterator_count", 92 Help: "Number of times the ITERATOR operation is done.", 93 }), 94 WriteBatchCounter: prometheus.NewCounter(prometheus.CounterOpts{ 95 Namespace: m.Namespace, 96 Subsystem: subsystem, 97 Name: "write_batch_count", 98 Help: "Number of times the WRITE_BATCH operation is done.", 99 }), 100 WriteBatchFailCounter: prometheus.NewCounter(prometheus.CounterOpts{ 101 Namespace: m.Namespace, 102 Subsystem: subsystem, 103 Name: "write_batch_fail_count", 104 Help: "Number of times the WRITE_BATCH operation failed.", 105 }), 106 } 107 } 108 109 func (s *DB) Metrics() []prometheus.Collector { 110 return m.PrometheusCollectorsFromFields(s.metrics) 111 }