From 489d9b9184f06d1c7e38f5895d0b0e42a9839aa3 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 14 Jun 2018 16:09:32 +0400 Subject: [PATCH] more metrics --- consensus/metrics.go | 9 +++++++++ consensus/state.go | 11 +++++++---- node/node.go | 34 ++++++++++++++++++++++++++++++++++ types/block.go | 9 +++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index c4cd0334..c099eb0b 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -13,6 +13,12 @@ type Metrics struct { MissingValidators metrics.Gauge // number of validators who tried to double sign ByzantineValidators metrics.Gauge + // number of transactions + NumTxs metrics.Gauge + // total number of transactions + TotalTxs metrics.Counter + // size of the block + BlockSizeBytes metrics.Gauge } // NopMetrics returns no-op Metrics. @@ -22,5 +28,8 @@ func NopMetrics() *Metrics { Validators: discard.NewGauge(), MissingValidators: discard.NewGauge(), ByzantineValidators: discard.NewGauge(), + NumTxs: discard.NewGauge(), + TotalTxs: discard.NewCounter(), + BlockSizeBytes: discard.NewGauge(), } } diff --git a/consensus/state.go b/consensus/state.go index 8c07f9ea..56d5a9ce 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1281,7 +1281,7 @@ func (cs *ConsensusState) finalizeCommit(height int64) { fail.Fail() // XXX - cs.recordValidatorMetrics(height, block) + cs.recordMetrics(height, block) // NewHeightStep! cs.updateToState(stateCopy) @@ -1298,11 +1298,10 @@ func (cs *ConsensusState) finalizeCommit(height int64) { // * cs.StartTime is set to when we will start round0. } -func (cs *ConsensusState) recordValidatorMetrics(height int64, block *types.Block) { +func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) { heightStr := fmt.Sprintf("%d", height) cs.metrics.Validators.With("height", heightStr).Set(float64(cs.Validators.Size())) - missingValidators := 0 for i := range cs.Validators.Validators { var vote *types.Vote @@ -1314,8 +1313,12 @@ func (cs *ConsensusState) recordValidatorMetrics(height int64, block *types.Bloc } } cs.metrics.MissingValidators.With("height", heightStr).Set(float64(missingValidators)) - cs.metrics.ByzantineValidators.With("height", heightStr).Set(float64(len(block.Evidence.Evidence))) + + cs.metrics.NumTxs.With("height", heightStr).Set(float64(block.NumTxs)) + cs.metrics.TotalTxs.Add(float64(block.NumTxs)) + + cs.metrics.BlockSizeBytes.With("height", heightStr).Set(float64(block.Size())) } //----------------------------------------------------------------------------- diff --git a/node/node.go b/node/node.go index 89d21d1a..27ef74f8 100644 --- a/node/node.go +++ b/node/node.go @@ -252,6 +252,7 @@ func NewNode(config *cfg.Config, Name: "height", Help: "Height of the chain.", }, []string{}), + Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ Subsystem: "consensus", Name: "validators", @@ -267,6 +268,39 @@ func NewNode(config *cfg.Config, Name: "byzantine_validators", Help: "Number of validators who tried to double sign, partitioned by height.", }, []string{"height"}), + + // BlockInterval: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ + // Subsystem: "consensus", + // Name: "block_interval", + // Help: "Time between this and the last block, partitioned by height.", + // }, []string{"height"}), + // BlockTime: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ + // Subsystem: "consensus", + // Name: "time_to_create_block", + // Help: "Time to create a block (from sending a proposal to commit), partitioned by height", + // }, []string{"height"}), + // TimeBetweenBlocks: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ + // Subsystem: "consensus", + // Name: "time_between_blocks", + // Help: "Time between committing the last block and (receiving/sending a proposal), partitioned by height", + // }, []string{"height"}), + + NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "num_txs", + Help: "Number of transactions, partitioned by height.", + }, []string{"height"}), + TotalTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Subsystem: "consensus", + Name: "total_txs", + Help: "Total number of transactions.", + }, []string{}), + + BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "block_size_bytes", + Help: "Size of the block, partitioned by height.", + }, []string{"height"}), } consensusState := cs.NewConsensusState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evidencePool, metrics) diff --git a/types/block.go b/types/block.go index 3004672c..6adc0c4c 100644 --- a/types/block.go +++ b/types/block.go @@ -135,6 +135,15 @@ func (b *Block) HashesTo(hash []byte) bool { return bytes.Equal(b.Hash(), hash) } +// Size returns size of the block in bytes. +func (b *Block) Size() int { + bz, err := cdc.MarshalBinaryBare(b) + if err != nil { + return 0 + } + return len(bz) +} + // String returns a string representation of the block func (b *Block) String() string { return b.StringIndented("")