github.com/evdatsion/aphelion-dpos-bft@v0.32.1/consensus/metrics.go (about) 1 package consensus 2 3 import ( 4 "github.com/go-kit/kit/metrics" 5 "github.com/go-kit/kit/metrics/discard" 6 7 prometheus "github.com/go-kit/kit/metrics/prometheus" 8 stdprometheus "github.com/prometheus/client_golang/prometheus" 9 ) 10 11 const ( 12 // MetricsSubsystem is a subsystem shared by all metrics exposed by this 13 // package. 14 MetricsSubsystem = "consensus" 15 ) 16 17 // Metrics contains metrics exposed by this package. 18 type Metrics struct { 19 // Height of the chain. 20 Height metrics.Gauge 21 22 // Number of rounds. 23 Rounds metrics.Gauge 24 25 // Number of validators. 26 Validators metrics.Gauge 27 // Total power of all validators. 28 ValidatorsPower metrics.Gauge 29 // Number of validators who did not sign. 30 MissingValidators metrics.Gauge 31 // Total power of the missing validators. 32 MissingValidatorsPower metrics.Gauge 33 // Number of validators who tried to double sign. 34 ByzantineValidators metrics.Gauge 35 // Total power of the byzantine validators. 36 ByzantineValidatorsPower metrics.Gauge 37 38 // Time between this and the last block. 39 BlockIntervalSeconds metrics.Gauge 40 41 // Number of transactions. 42 NumTxs metrics.Gauge 43 // Size of the block. 44 BlockSizeBytes metrics.Gauge 45 // Total number of transactions. 46 TotalTxs metrics.Gauge 47 // The latest block height. 48 CommittedHeight metrics.Gauge 49 // Whether or not a node is fast syncing. 1 if yes, 0 if no. 50 FastSyncing metrics.Gauge 51 52 // Number of blockparts transmitted by peer. 53 BlockParts metrics.Counter 54 } 55 56 // PrometheusMetrics returns Metrics build using Prometheus client library. 57 // Optionally, labels can be provided along with their values ("foo", 58 // "fooValue"). 59 func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { 60 labels := []string{} 61 for i := 0; i < len(labelsAndValues); i += 2 { 62 labels = append(labels, labelsAndValues[i]) 63 } 64 return &Metrics{ 65 Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 66 Namespace: namespace, 67 Subsystem: MetricsSubsystem, 68 Name: "height", 69 Help: "Height of the chain.", 70 }, labels).With(labelsAndValues...), 71 Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 72 Namespace: namespace, 73 Subsystem: MetricsSubsystem, 74 Name: "rounds", 75 Help: "Number of rounds.", 76 }, labels).With(labelsAndValues...), 77 78 Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 79 Namespace: namespace, 80 Subsystem: MetricsSubsystem, 81 Name: "validators", 82 Help: "Number of validators.", 83 }, labels).With(labelsAndValues...), 84 ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 85 Namespace: namespace, 86 Subsystem: MetricsSubsystem, 87 Name: "validators_power", 88 Help: "Total power of all validators.", 89 }, labels).With(labelsAndValues...), 90 MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 91 Namespace: namespace, 92 Subsystem: MetricsSubsystem, 93 Name: "missing_validators", 94 Help: "Number of validators who did not sign.", 95 }, labels).With(labelsAndValues...), 96 MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 97 Namespace: namespace, 98 Subsystem: MetricsSubsystem, 99 Name: "missing_validators_power", 100 Help: "Total power of the missing validators.", 101 }, labels).With(labelsAndValues...), 102 ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 103 Namespace: namespace, 104 Subsystem: MetricsSubsystem, 105 Name: "byzantine_validators", 106 Help: "Number of validators who tried to double sign.", 107 }, labels).With(labelsAndValues...), 108 ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 109 Namespace: namespace, 110 Subsystem: MetricsSubsystem, 111 Name: "byzantine_validators_power", 112 Help: "Total power of the byzantine validators.", 113 }, labels).With(labelsAndValues...), 114 115 BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 116 Namespace: namespace, 117 Subsystem: MetricsSubsystem, 118 Name: "block_interval_seconds", 119 Help: "Time between this and the last block.", 120 }, labels).With(labelsAndValues...), 121 122 NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 123 Namespace: namespace, 124 Subsystem: MetricsSubsystem, 125 Name: "num_txs", 126 Help: "Number of transactions.", 127 }, labels).With(labelsAndValues...), 128 BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 129 Namespace: namespace, 130 Subsystem: MetricsSubsystem, 131 Name: "block_size_bytes", 132 Help: "Size of the block.", 133 }, labels).With(labelsAndValues...), 134 TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 135 Namespace: namespace, 136 Subsystem: MetricsSubsystem, 137 Name: "total_txs", 138 Help: "Total number of transactions.", 139 }, labels).With(labelsAndValues...), 140 CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 141 Namespace: namespace, 142 Subsystem: MetricsSubsystem, 143 Name: "latest_block_height", 144 Help: "The latest block height.", 145 }, labels).With(labelsAndValues...), 146 FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 147 Namespace: namespace, 148 Subsystem: MetricsSubsystem, 149 Name: "fast_syncing", 150 Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.", 151 }, labels).With(labelsAndValues...), 152 BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ 153 Namespace: namespace, 154 Subsystem: MetricsSubsystem, 155 Name: "block_parts", 156 Help: "Number of blockparts transmitted by peer.", 157 }, append(labels, "peer_id")).With(labelsAndValues...), 158 } 159 } 160 161 // NopMetrics returns no-op Metrics. 162 func NopMetrics() *Metrics { 163 return &Metrics{ 164 Height: discard.NewGauge(), 165 166 Rounds: discard.NewGauge(), 167 168 Validators: discard.NewGauge(), 169 ValidatorsPower: discard.NewGauge(), 170 MissingValidators: discard.NewGauge(), 171 MissingValidatorsPower: discard.NewGauge(), 172 ByzantineValidators: discard.NewGauge(), 173 ByzantineValidatorsPower: discard.NewGauge(), 174 175 BlockIntervalSeconds: discard.NewGauge(), 176 177 NumTxs: discard.NewGauge(), 178 BlockSizeBytes: discard.NewGauge(), 179 TotalTxs: discard.NewGauge(), 180 CommittedHeight: discard.NewGauge(), 181 FastSyncing: discard.NewGauge(), 182 BlockParts: discard.NewCounter(), 183 } 184 }