github.com/ethersphere/bee/v2@v2.2.0/pkg/sharky/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 sharky 6 7 import ( 8 m "github.com/ethersphere/bee/v2/pkg/metrics" 9 "github.com/prometheus/client_golang/prometheus" 10 ) 11 12 // metrics groups sharky related prometheus counters. 13 type metrics struct { 14 TotalWriteCalls prometheus.Counter 15 TotalWriteCallsErr prometheus.Counter 16 TotalReadCalls prometheus.Counter 17 TotalReadCallsErr prometheus.Counter 18 TotalReleaseCalls prometheus.Counter 19 TotalReleaseCallsErr prometheus.Counter 20 ShardCount prometheus.Gauge 21 CurrentShardSize *prometheus.GaugeVec 22 ShardFragmentation *prometheus.GaugeVec 23 LastAllocatedShardSlot *prometheus.GaugeVec 24 LastReleasedShardSlot *prometheus.GaugeVec 25 } 26 27 // newMetrics is a convenient constructor for creating new metrics. 28 func newMetrics() metrics { 29 const subsystem = "sharky" 30 31 return metrics{ 32 TotalWriteCalls: prometheus.NewCounter(prometheus.CounterOpts{ 33 Namespace: m.Namespace, 34 Subsystem: subsystem, 35 Name: "total_write_calls", 36 Help: "The total write calls made.", 37 }), 38 TotalWriteCallsErr: prometheus.NewCounter(prometheus.CounterOpts{ 39 Namespace: m.Namespace, 40 Subsystem: subsystem, 41 Name: "total_write_calls_err", 42 Help: "The total write calls ended up with error.", 43 }), 44 TotalReadCalls: prometheus.NewCounter(prometheus.CounterOpts{ 45 Namespace: m.Namespace, 46 Subsystem: subsystem, 47 Name: "total_read_calls", 48 Help: "The total read calls made.", 49 }), 50 TotalReadCallsErr: prometheus.NewCounter(prometheus.CounterOpts{ 51 Namespace: m.Namespace, 52 Subsystem: subsystem, 53 Name: "total_read_calls_err", 54 Help: "The total read calls ended up with error.", 55 }), 56 TotalReleaseCalls: prometheus.NewCounter(prometheus.CounterOpts{ 57 Namespace: m.Namespace, 58 Subsystem: subsystem, 59 Name: "total_release_calls", 60 Help: "The total release calls made.", 61 }), 62 TotalReleaseCallsErr: prometheus.NewCounter(prometheus.CounterOpts{ 63 Namespace: m.Namespace, 64 Subsystem: subsystem, 65 Name: "total_release_calls_err", 66 Help: "The total release calls ended up with error.", 67 }), 68 ShardCount: prometheus.NewGauge(prometheus.GaugeOpts{ 69 Namespace: m.Namespace, 70 Subsystem: subsystem, 71 Name: "shard_count", 72 Help: "The number of shards.", 73 }), 74 CurrentShardSize: prometheus.NewGaugeVec( 75 prometheus.GaugeOpts{ 76 Namespace: m.Namespace, 77 Subsystem: subsystem, 78 Name: "current_shard_size", 79 Help: "The current size of the shard derived as: length in bytes/data length per chunk", 80 }, 81 []string{"current_shard_size"}, 82 ), 83 ShardFragmentation: prometheus.NewGaugeVec( 84 prometheus.GaugeOpts{ 85 Namespace: m.Namespace, 86 Subsystem: subsystem, 87 Name: "shard_fragmentation", 88 Help: ` 89 The total fragmentation of the files on disc for current shard. This is obtained by keeping track of the difference 90 between actual lengths of chunks and the length of slot. 91 `, 92 }, []string{"shard_fragmentation"}, 93 ), 94 LastAllocatedShardSlot: prometheus.NewGaugeVec( 95 prometheus.GaugeOpts{ 96 Namespace: m.Namespace, 97 Subsystem: subsystem, 98 Name: "last_allocated_shard_slot", 99 Help: "The slot no of the last allocated entry per shard", 100 }, 101 []string{"shard_slot_no"}, 102 ), 103 LastReleasedShardSlot: prometheus.NewGaugeVec( 104 prometheus.GaugeOpts{ 105 Namespace: m.Namespace, 106 Subsystem: subsystem, 107 Name: "last_released_shard_slot", 108 Help: "The slot no of the last released slot", 109 }, 110 []string{"shard_slot_no"}, 111 ), 112 } 113 } 114 115 // Metrics returns set of prometheus collectors. 116 func (s *Store) Metrics() []prometheus.Collector { 117 return m.PrometheusCollectorsFromFields(s.metrics) 118 }