github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/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.Gauge 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 59 // Number of blockparts transmitted by peer. 60 BlockParts metrics.Counter 61 } 62 63 // PrometheusMetrics returns Metrics build using Prometheus client library. 64 // Optionally, labels can be provided along with their values ("foo", 65 // "fooValue"). 66 func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { 67 labels := []string{} 68 for i := 0; i < len(labelsAndValues); i += 2 { 69 labels = append(labels, labelsAndValues[i]) 70 } 71 return &Metrics{ 72 Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 73 Namespace: namespace, 74 Subsystem: MetricsSubsystem, 75 Name: "height", 76 Help: "Height of the chain.", 77 }, labels).With(labelsAndValues...), 78 Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 79 Namespace: namespace, 80 Subsystem: MetricsSubsystem, 81 Name: "rounds", 82 Help: "Number of rounds.", 83 }, labels).With(labelsAndValues...), 84 85 Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 86 Namespace: namespace, 87 Subsystem: MetricsSubsystem, 88 Name: "validators", 89 Help: "Number of validators.", 90 }, labels).With(labelsAndValues...), 91 ValidatorLastSignedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 92 Namespace: namespace, 93 Subsystem: MetricsSubsystem, 94 Name: "validator_last_signed_height", 95 Help: "Last signed height for a validator", 96 }, append(labels, "validator_address")).With(labelsAndValues...), 97 ValidatorMissedBlocks: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 98 Namespace: namespace, 99 Subsystem: MetricsSubsystem, 100 Name: "validator_missed_blocks", 101 Help: "Total missed blocks for a validator", 102 }, append(labels, "validator_address")).With(labelsAndValues...), 103 ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 104 Namespace: namespace, 105 Subsystem: MetricsSubsystem, 106 Name: "validators_power", 107 Help: "Total power of all validators.", 108 }, labels).With(labelsAndValues...), 109 ValidatorPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 110 Namespace: namespace, 111 Subsystem: MetricsSubsystem, 112 Name: "validator_power", 113 Help: "Power of a validator", 114 }, append(labels, "validator_address")).With(labelsAndValues...), 115 MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 116 Namespace: namespace, 117 Subsystem: MetricsSubsystem, 118 Name: "missing_validators", 119 Help: "Number of validators who did not sign.", 120 }, labels).With(labelsAndValues...), 121 MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 122 Namespace: namespace, 123 Subsystem: MetricsSubsystem, 124 Name: "missing_validators_power", 125 Help: "Total power of the missing validators.", 126 }, labels).With(labelsAndValues...), 127 ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 128 Namespace: namespace, 129 Subsystem: MetricsSubsystem, 130 Name: "byzantine_validators", 131 Help: "Number of validators who tried to double sign.", 132 }, labels).With(labelsAndValues...), 133 ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 134 Namespace: namespace, 135 Subsystem: MetricsSubsystem, 136 Name: "byzantine_validators_power", 137 Help: "Total power of the byzantine validators.", 138 }, labels).With(labelsAndValues...), 139 140 BlockIntervalSeconds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 141 Namespace: namespace, 142 Subsystem: MetricsSubsystem, 143 Name: "block_interval_seconds", 144 Help: "Time between this and the last block.", 145 }, labels).With(labelsAndValues...), 146 147 NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 148 Namespace: namespace, 149 Subsystem: MetricsSubsystem, 150 Name: "num_txs", 151 Help: "Number of transactions.", 152 }, labels).With(labelsAndValues...), 153 BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 154 Namespace: namespace, 155 Subsystem: MetricsSubsystem, 156 Name: "block_size_bytes", 157 Help: "Size of the block.", 158 }, labels).With(labelsAndValues...), 159 TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 160 Namespace: namespace, 161 Subsystem: MetricsSubsystem, 162 Name: "total_txs", 163 Help: "Total number of transactions.", 164 }, labels).With(labelsAndValues...), 165 CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 166 Namespace: namespace, 167 Subsystem: MetricsSubsystem, 168 Name: "latest_block_height", 169 Help: "The latest block height.", 170 }, labels).With(labelsAndValues...), 171 FastSyncing: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ 172 Namespace: namespace, 173 Subsystem: MetricsSubsystem, 174 Name: "fast_syncing", 175 Help: "Whether or not a node is fast syncing. 1 if yes, 0 if no.", 176 }, labels).With(labelsAndValues...), 177 BlockParts: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ 178 Namespace: namespace, 179 Subsystem: MetricsSubsystem, 180 Name: "block_parts", 181 Help: "Number of blockparts transmitted by peer.", 182 }, append(labels, "peer_id")).With(labelsAndValues...), 183 } 184 } 185 186 // NopMetrics returns no-op Metrics. 187 func NopMetrics() *Metrics { 188 return &Metrics{ 189 Height: discard.NewGauge(), 190 191 ValidatorLastSignedHeight: discard.NewGauge(), 192 193 Rounds: discard.NewGauge(), 194 195 Validators: discard.NewGauge(), 196 ValidatorsPower: discard.NewGauge(), 197 ValidatorPower: discard.NewGauge(), 198 ValidatorMissedBlocks: discard.NewGauge(), 199 MissingValidators: discard.NewGauge(), 200 MissingValidatorsPower: discard.NewGauge(), 201 ByzantineValidators: discard.NewGauge(), 202 ByzantineValidatorsPower: discard.NewGauge(), 203 204 BlockIntervalSeconds: discard.NewGauge(), 205 206 NumTxs: discard.NewGauge(), 207 BlockSizeBytes: discard.NewGauge(), 208 TotalTxs: discard.NewGauge(), 209 CommittedHeight: discard.NewGauge(), 210 FastSyncing: discard.NewGauge(), 211 BlockParts: discard.NewCounter(), 212 } 213 }