github.com/arcology-network/consensus-engine@v1.9.0/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 // ValidatorLastSignedHeight of a validator. 23 ValidatorLastSignedHeight metrics.Gauge 24 25 // Number of rounds. 26 Rounds metrics.Gauge 27 28 // Number of validators. 29 Validators metrics.Gauge 30 // Total power of all validators. 31 ValidatorsPower metrics.Gauge 32 // Power of a validator. 33 ValidatorPower metrics.Gauge 34 // Amount of blocks missed by a validator. 35 ValidatorMissedBlocks metrics.Gauge 36 // Number of validators who did not sign. 37 MissingValidators metrics.Gauge 38 // Total power of the missing validators. 39 MissingValidatorsPower metrics.Gauge 40 // Number of validators who tried to double sign. 41 ByzantineValidators metrics.Gauge 42 // Total power of the byzantine validators. 43 ByzantineValidatorsPower metrics.Gauge 44 45 // Time between this and the last block. 46 BlockIntervalSeconds metrics.Histogram 47 48 // Number of transactions. 49 NumTxs metrics.Gauge 50 // Size of the block. 51 BlockSizeBytes metrics.Gauge 52 // Total number of transactions. 53 TotalTxs metrics.Gauge 54 // The latest block height. 55 CommittedHeight metrics.Gauge 56 // Whether or not a node is fast syncing. 1 if yes, 0 if no. 57 FastSyncing metrics.Gauge 58 // Whether or not a node is state syncing. 1 if yes, 0 if no. 59 StateSyncing metrics.Gauge 60 61 // Number of blockparts transmitted by peer. 62 BlockParts metrics.Counter 63 64 // Total number of transactions processed. 65 TxsProcessed metrics.Counter 66 // The duration between two seccessive blocks. 67 BlockInterval metrics.Histogram 68 BlockIntervalGauge metrics.Gauge 69 // Real time TPS. 70 RealTimeTPS metrics.Gauge 71 // The time used on reaching consensus. 72 ReachingConsensusSeconds metrics.Histogram 73 ReachingConsensusSecondsGauge metrics.Gauge 74 } 75 76 // PrometheusMetrics returns Metrics build using Prometheus client library. 77 // Optionally, labels can be provided along with their values ("foo", 78 // "fooValue"). 79 func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { 80 labels := []string{} 81 for i := 0; i < len(labelsAndValues); i += 2 { 82 labels = append(labels, labelsAndValues[i]) 83 } 84 return &Metrics{ 85 Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 86 Namespace: namespace, 87 Subsystem: MetricsSubsystem, 88 Name: "height", 89 Help: "Height of the chain.", 90 }, labels).With(labelsAndValues...), 91 Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 92 Namespace: namespace, 93 Subsystem: MetricsSubsystem, 94 Name: "rounds", 95 Help: "Number of rounds.", 96 }, labels).With(labelsAndValues...), 97 98 Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 99 Namespace: namespace, 100 Subsystem: MetricsSubsystem, 101 Name: "validators", 102 Help: "Number of validators.", 103 }, labels).With(labelsAndValues...), 104 ValidatorLastSignedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 105 Namespace: namespace, 106 Subsystem: MetricsSubsystem, 107 Name: "validator_last_signed_height", 108 Help: "Last signed height for a validator", 109 }, append(labels, "validator_address")).With(labelsAndValues...), 110 ValidatorMissedBlocks: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 111 Namespace: namespace, 112 Subsystem: MetricsSubsystem, 113 Name: "validator_missed_blocks", 114 Help: "Total missed blocks for a validator", 115 }, append(labels, "validator_address")).With(labelsAndValues...), 116 ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 117 Namespace: namespace, 118 Subsystem: MetricsSubsystem, 119 Name: "validators_power", 120 Help: "Total power of all validators.", 121 }, labels).With(labelsAndValues...), 122 ValidatorPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 123 Namespace: namespace, 124 Subsystem: MetricsSubsystem, 125 Name: "validator_power", 126 Help: "Power of a validator", 127 }, append(labels, "validator_address")).With(labelsAndValues...), 128 MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 129 Namespace: namespace, 130 Subsystem: MetricsSubsystem, 131 Name: "missing_validators", 132 Help: "Number of validators who did not sign.", 133 }, labels).With(labelsAndValues...), 134 MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 135 Namespace: namespace, 136 Subsystem: MetricsSubsystem, 137 Name: "missing_validators_power", 138 Help: "Total power of the missing validators.", 139 }, labels).With(labelsAndValues...), 140 ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 141 Namespace: namespace, 142 Subsystem: MetricsSubsystem, 143 Name: "byzantine_validators", 144 Help: "Number of validators who tried to double sign.", 145 }, labels).With(labelsAndValues...), 146 ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 147 Namespace: namespace, 148 Subsystem: MetricsSubsystem, 149 Name: "byzantine_validators_power", 150 Help: "Total power of the byzantine validators.", 151 }, labels).With(labelsAndValues...), 152 BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ 153 Namespace: namespace, 154 Subsystem: MetricsSubsystem, 155 Name: "block_interval_seconds", 156 Help: "Time between this and the last block.", 157 }, labels).With(labelsAndValues...), 158 NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 159 Namespace: namespace, 160 Subsystem: MetricsSubsystem, 161 Name: "num_txs", 162 Help: "Number of transactions.", 163 }, labels).With(labelsAndValues...), 164 BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 165 Namespace: namespace, 166 Subsystem: MetricsSubsystem, 167 Name: "block_size_bytes", 168 Help: "Size of the block.", 169 }, labels).With(labelsAndValues...), 170 TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 171 Namespace: namespace, 172 Subsystem: MetricsSubsystem, 173 Name: "total_txs", 174 Help: "Total number of transactions.", 175 }, labels).With(labelsAndValues...), 176 CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 177 Namespace: namespace, 178 Subsystem: MetricsSubsystem, 179 Name: "latest_block_height", 180 Help: "The latest block height.", 181 }, labels).With(labelsAndValues...), 182 FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 183 Namespace: namespace, 184 Subsystem: MetricsSubsystem, 185 Name: "fast_syncing", 186 Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.", 187 }, labels).With(labelsAndValues...), 188 StateSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 189 Namespace: namespace, 190 Subsystem: MetricsSubsystem, 191 Name: "state_syncing", 192 Help: "Whether or not a node is state syncing. 1 if yes, 0 if no.", 193 }, labels).With(labelsAndValues...), 194 BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ 195 Namespace: namespace, 196 Subsystem: MetricsSubsystem, 197 Name: "block_parts", 198 Help: "Number of blockparts transmitted by peer.", 199 }, append(labels, "peer_id")).With(labelsAndValues...), 200 TxsProcessed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ 201 Subsystem: MetricsSubsystem, 202 Name: "processed_txs_total", 203 Help: "Total number of transactions processed", 204 }, labels).With(labelsAndValues...), 205 BlockInterval: prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ 206 Subsystem: MetricsSubsystem, 207 Name: "block_interval_seconds", 208 Help: "The duration between two seccessive blocks", 209 }, labels).With(labelsAndValues...), 210 BlockIntervalGauge: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 211 Subsystem: MetricsSubsystem, 212 Name: "block_interval_seconds_gauge", 213 Help: "The duration between two seccessive blocks", 214 }, labels).With(labelsAndValues...), 215 RealTimeTPS: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 216 Subsystem: MetricsSubsystem, 217 Name: "real_time_tps", 218 Help: "Real time TPS", 219 }, labels).With(labelsAndValues...), 220 ReachingConsensusSeconds: prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ 221 Subsystem: MetricsSubsystem, 222 Name: "reaching_consensus_seconds", 223 Help: "The time used on reaching consensus.", 224 }, labels).With(labelsAndValues...), 225 ReachingConsensusSecondsGauge: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 226 Subsystem: MetricsSubsystem, 227 Name: "reaching_consensus_seconds_gauge", 228 Help: "The time used on reaching consensus.", 229 }, labels).With(labelsAndValues...), 230 } 231 } 232 233 // NopMetrics returns no-op Metrics. 234 func NopMetrics() *Metrics { 235 return &Metrics{ 236 Height: discard.NewGauge(), 237 238 ValidatorLastSignedHeight: discard.NewGauge(), 239 240 Rounds: discard.NewGauge(), 241 242 Validators: discard.NewGauge(), 243 ValidatorsPower: discard.NewGauge(), 244 ValidatorPower: discard.NewGauge(), 245 ValidatorMissedBlocks: discard.NewGauge(), 246 MissingValidators: discard.NewGauge(), 247 MissingValidatorsPower: discard.NewGauge(), 248 ByzantineValidators: discard.NewGauge(), 249 ByzantineValidatorsPower: discard.NewGauge(), 250 251 BlockIntervalSeconds: discard.NewHistogram(), 252 253 NumTxs: discard.NewGauge(), 254 BlockSizeBytes: discard.NewGauge(), 255 TotalTxs: discard.NewGauge(), 256 CommittedHeight: discard.NewGauge(), 257 FastSyncing: discard.NewGauge(), 258 StateSyncing: discard.NewGauge(), 259 BlockParts: discard.NewCounter(), 260 TxsProcessed: discard.NewCounter(), 261 BlockInterval: discard.NewHistogram(), 262 BlockIntervalGauge: discard.NewGauge(), 263 RealTimeTPS: discard.NewGauge(), 264 ReachingConsensusSeconds: discard.NewHistogram(), 265 ReachingConsensusSecondsGauge: discard.NewGauge(), 266 } 267 }