github.com/koko1123/flow-go-1@v0.29.6/module/metrics/compliance.go (about) 1 package metrics 2 3 import ( 4 "time" 5 6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus/promauto" 8 9 "github.com/koko1123/flow-go-1/model/flow" 10 ) 11 12 type ComplianceCollector struct { 13 finalizedHeight prometheus.Gauge 14 sealedHeight prometheus.Gauge 15 finalizedBlocks *prometheus.CounterVec 16 sealedBlocks prometheus.Counter 17 blockProposalDuration prometheus.Counter 18 finalizedPayload *prometheus.CounterVec 19 sealedPayload *prometheus.CounterVec 20 lastBlockFinalizedAt time.Time 21 finalizedBlocksPerSecond prometheus.Summary 22 committedEpochFinalView prometheus.Gauge 23 currentEpochCounter prometheus.Gauge 24 currentEpochPhase prometheus.Gauge 25 currentEpochFinalView prometheus.Gauge 26 currentDKGPhase1FinalView prometheus.Gauge 27 currentDKGPhase2FinalView prometheus.Gauge 28 currentDKGPhase3FinalView prometheus.Gauge 29 epochEmergencyFallbackTriggered prometheus.Gauge 30 } 31 32 func NewComplianceCollector() *ComplianceCollector { 33 34 cc := &ComplianceCollector{ 35 36 currentEpochCounter: promauto.NewGauge(prometheus.GaugeOpts{ 37 Name: "current_epoch_counter", 38 Namespace: namespaceConsensus, 39 Subsystem: subsystemCompliance, 40 Help: "the current epoch's counter", 41 }), 42 43 currentEpochPhase: promauto.NewGauge(prometheus.GaugeOpts{ 44 Name: "current_epoch_phase", 45 Namespace: namespaceConsensus, 46 Subsystem: subsystemCompliance, 47 Help: "the current epoch's phase", 48 }), 49 50 committedEpochFinalView: promauto.NewGauge(prometheus.GaugeOpts{ 51 Name: "committed_epoch_final_view", 52 Namespace: namespaceConsensus, 53 Subsystem: subsystemCompliance, 54 Help: "the final view of the committed epoch with the greatest counter", 55 }), 56 57 currentEpochFinalView: promauto.NewGauge(prometheus.GaugeOpts{ 58 Name: "current_epoch_final_view", 59 Namespace: namespaceConsensus, 60 Subsystem: subsystemCompliance, 61 Help: "the final view of the current epoch", 62 }), 63 64 currentDKGPhase1FinalView: promauto.NewGauge(prometheus.GaugeOpts{ 65 Name: "current_dkg_phase1_final_view", 66 Namespace: namespaceConsensus, 67 Subsystem: subsystemCompliance, 68 Help: "the final view of phase 1 of the current epochs DKG", 69 }), 70 currentDKGPhase2FinalView: promauto.NewGauge(prometheus.GaugeOpts{ 71 Name: "current_dkg_phase2_final_view", 72 Namespace: namespaceConsensus, 73 Subsystem: subsystemCompliance, 74 Help: "the final view of phase 2 of current epochs DKG", 75 }), 76 77 currentDKGPhase3FinalView: promauto.NewGauge(prometheus.GaugeOpts{ 78 Name: "current_dkg_phase3_final_view", 79 Namespace: namespaceConsensus, 80 Subsystem: subsystemCompliance, 81 Help: "the final view of phase 3 of the current epochs DKG (a successful DKG will end shortly after this view)", 82 }), 83 84 finalizedHeight: promauto.NewGauge(prometheus.GaugeOpts{ 85 Name: "finalized_height", 86 Namespace: namespaceConsensus, 87 Subsystem: subsystemCompliance, 88 Help: "the last finalized height", 89 }), 90 91 sealedHeight: promauto.NewGauge(prometheus.GaugeOpts{ 92 Name: "sealed_height", 93 Namespace: namespaceConsensus, 94 Subsystem: subsystemCompliance, 95 Help: "the last sealed height", 96 }), 97 98 finalizedBlocks: promauto.NewCounterVec(prometheus.CounterOpts{ 99 Name: "finalized_blocks_total", 100 Namespace: namespaceConsensus, 101 Subsystem: subsystemCompliance, 102 Help: "the number of finalized blocks", 103 }, []string{LabelProposer}), 104 105 sealedBlocks: promauto.NewCounter(prometheus.CounterOpts{ 106 Name: "sealed_blocks_total", 107 Namespace: namespaceConsensus, 108 Subsystem: subsystemCompliance, 109 Help: "the number of sealed blocks", 110 }), 111 112 blockProposalDuration: promauto.NewCounter(prometheus.CounterOpts{ 113 Name: "consensus_committee_block_proposal_duration_seconds_total", 114 Namespace: namespaceConsensus, 115 Subsystem: subsystemCompliance, 116 Help: "time spent processing block proposals in seconds", 117 }), 118 119 finalizedPayload: promauto.NewCounterVec(prometheus.CounterOpts{ 120 Name: "finalized_payload_total", 121 Namespace: namespaceConsensus, 122 Subsystem: subsystemCompliance, 123 Help: "the number of resources in finalized blocks", 124 }, []string{LabelResource}), 125 126 sealedPayload: promauto.NewCounterVec(prometheus.CounterOpts{ 127 Name: "sealed_payload_total", 128 Namespace: namespaceConsensus, 129 Subsystem: subsystemCompliance, 130 Help: "the number of resources in sealed blocks", 131 }, []string{LabelResource}), 132 133 finalizedBlocksPerSecond: promauto.NewSummary(prometheus.SummaryOpts{ 134 Name: "finalized_blocks_per_second", 135 Namespace: namespaceConsensus, 136 Subsystem: subsystemCompliance, 137 Help: "the number of finalized blocks per second/the finalized block rate", 138 Objectives: map[float64]float64{ 139 0.01: 0.001, 140 0.1: 0.01, 141 0.5: 0.05, 142 0.9: 0.01, 143 0.99: 0.001, 144 }, 145 MaxAge: 10 * time.Minute, 146 AgeBuckets: 5, 147 BufCap: 500, 148 }), 149 150 epochEmergencyFallbackTriggered: promauto.NewGauge(prometheus.GaugeOpts{ 151 Name: "epoch_fallback_triggered", 152 Namespace: namespaceConsensus, 153 Subsystem: subsystemCompliance, 154 Help: "indicates whether epoch emergency fallback is triggered; if >0, the fallback is triggered", 155 }), 156 } 157 158 return cc 159 } 160 161 // FinalizedHeight sets the finalized height. 162 func (cc *ComplianceCollector) FinalizedHeight(height uint64) { 163 cc.finalizedHeight.Set(float64(height)) 164 } 165 166 // BlockFinalized reports metrics about finalized blocks. 167 func (cc *ComplianceCollector) BlockFinalized(block *flow.Block) { 168 now := time.Now() 169 if !cc.lastBlockFinalizedAt.IsZero() { 170 cc.finalizedBlocksPerSecond.Observe(1 / now.Sub(cc.lastBlockFinalizedAt).Seconds()) 171 } 172 cc.lastBlockFinalizedAt = now 173 174 cc.finalizedBlocks.With(prometheus.Labels{LabelProposer: block.Header.ProposerID.String()}).Inc() 175 cc.finalizedPayload.With(prometheus.Labels{LabelResource: ResourceGuarantee}).Add(float64(len(block.Payload.Guarantees))) 176 cc.finalizedPayload.With(prometheus.Labels{LabelResource: ResourceSeal}).Add(float64(len(block.Payload.Seals))) 177 } 178 179 // SealedHeight sets the finalized height. 180 func (cc *ComplianceCollector) SealedHeight(height uint64) { 181 cc.sealedHeight.Set(float64(height)) 182 } 183 184 // BlockSealed reports metrics about sealed blocks. 185 func (cc *ComplianceCollector) BlockSealed(block *flow.Block) { 186 cc.sealedBlocks.Inc() 187 cc.sealedPayload.With(prometheus.Labels{LabelResource: ResourceGuarantee}).Add(float64(len(block.Payload.Guarantees))) 188 cc.sealedPayload.With(prometheus.Labels{LabelResource: ResourceSeal}).Add(float64(len(block.Payload.Seals))) 189 } 190 191 func (cc *ComplianceCollector) BlockProposalDuration(duration time.Duration) { 192 cc.blockProposalDuration.Add(duration.Seconds()) 193 } 194 195 func (cc *ComplianceCollector) CommittedEpochFinalView(view uint64) { 196 cc.committedEpochFinalView.Set(float64(view)) 197 } 198 199 func (cc *ComplianceCollector) CurrentEpochCounter(counter uint64) { 200 cc.currentEpochCounter.Set(float64(counter)) 201 } 202 203 func (cc *ComplianceCollector) CurrentEpochPhase(phase flow.EpochPhase) { 204 cc.currentEpochPhase.Set(float64(phase)) 205 } 206 207 func (cc *ComplianceCollector) CurrentEpochFinalView(view uint64) { 208 cc.currentEpochFinalView.Set(float64(view)) 209 } 210 211 func (cc *ComplianceCollector) CurrentDKGPhase1FinalView(view uint64) { 212 cc.currentDKGPhase1FinalView.Set(float64(view)) 213 } 214 215 func (cc *ComplianceCollector) CurrentDKGPhase2FinalView(view uint64) { 216 cc.currentDKGPhase2FinalView.Set(float64(view)) 217 } 218 219 func (cc *ComplianceCollector) CurrentDKGPhase3FinalView(view uint64) { 220 cc.currentDKGPhase3FinalView.Set(float64(view)) 221 } 222 223 func (cc *ComplianceCollector) EpochEmergencyFallbackTriggered() { 224 cc.epochEmergencyFallbackTriggered.Set(float64(1)) 225 }