more metrics

This commit is contained in:
Anton Kaliaev 2018-06-14 16:09:32 +04:00
parent 3cdf3b670d
commit 489d9b9184
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
4 changed files with 59 additions and 4 deletions

View File

@ -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(),
}
}

View File

@ -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()))
}
//-----------------------------------------------------------------------------

View File

@ -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)

View File

@ -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("")