extract metrics to provider, remove height label

This commit is contained in:
Anton Kaliaev 2018-06-15 14:23:34 +04:00
parent 489d9b9184
commit fad76e103b
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
4 changed files with 83 additions and 73 deletions

View File

@ -13,6 +13,8 @@ type Metrics struct {
MissingValidators metrics.Gauge MissingValidators metrics.Gauge
// number of validators who tried to double sign // number of validators who tried to double sign
ByzantineValidators metrics.Gauge ByzantineValidators metrics.Gauge
// time between this and the last block
BlockIntervalSeconds metrics.Histogram
// number of transactions // number of transactions
NumTxs metrics.Gauge NumTxs metrics.Gauge
// total number of transactions // total number of transactions
@ -24,12 +26,13 @@ type Metrics struct {
// NopMetrics returns no-op Metrics. // NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics { func NopMetrics() *Metrics {
return &Metrics{ return &Metrics{
Height: discard.NewCounter(), Height: discard.NewCounter(),
Validators: discard.NewGauge(), Validators: discard.NewGauge(),
MissingValidators: discard.NewGauge(), MissingValidators: discard.NewGauge(),
ByzantineValidators: discard.NewGauge(), ByzantineValidators: discard.NewGauge(),
NumTxs: discard.NewGauge(), BlockIntervalSeconds: discard.NewHistogram(),
TotalTxs: discard.NewCounter(), NumTxs: discard.NewGauge(),
BlockSizeBytes: discard.NewGauge(), TotalTxs: discard.NewCounter(),
BlockSizeBytes: discard.NewGauge(),
} }
} }

View File

@ -1299,9 +1299,7 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
} }
func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) { func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) {
heightStr := fmt.Sprintf("%d", height) cs.metrics.Validators.Set(float64(cs.Validators.Size()))
cs.metrics.Validators.With("height", heightStr).Set(float64(cs.Validators.Size()))
missingValidators := 0 missingValidators := 0
for i := range cs.Validators.Validators { for i := range cs.Validators.Validators {
var vote *types.Vote var vote *types.Vote
@ -1312,13 +1310,19 @@ func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) {
missingValidators++ missingValidators++
} }
} }
cs.metrics.MissingValidators.With("height", heightStr).Set(float64(missingValidators)) cs.metrics.MissingValidators.Set(float64(missingValidators))
cs.metrics.ByzantineValidators.With("height", heightStr).Set(float64(len(block.Evidence.Evidence))) cs.metrics.ByzantineValidators.Set(float64(len(block.Evidence.Evidence)))
cs.metrics.NumTxs.With("height", heightStr).Set(float64(block.NumTxs)) if height > 1 {
lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
cs.metrics.BlockIntervalSeconds.
Observe(block.Time.Sub(lastBlockMeta.Header.Time).Seconds())
}
cs.metrics.NumTxs.Set(float64(block.NumTxs))
cs.metrics.TotalTxs.Add(float64(block.NumTxs)) cs.metrics.TotalTxs.Add(float64(block.NumTxs))
cs.metrics.BlockSizeBytes.With("height", heightStr).Set(float64(block.Size())) cs.metrics.BlockSizeBytes.Set(float64(block.Size()))
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -85,10 +85,66 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()), proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config), DefaultGenesisDocProviderFunc(config),
DefaultDBProvider, DefaultDBProvider,
DefaultMetricsProvider,
logger, logger,
) )
} }
// MetricsProvider returns a consensus Metrics.
type MetricsProvider func() *cs.Metrics
// DefaultMetrics returns a consensus Metrics build using Prometheus client
// library.
func DefaultMetricsProvider() *cs.Metrics {
return &cs.Metrics{
Height: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Subsystem: "consensus",
Name: "height",
Help: "Height of the chain.",
}, []string{}),
Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "validators",
Help: "Number of validators who signed, partitioned by height.",
}, []string{}),
MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "missing_validators",
Help: "Number of validators who did not sign, partitioned by height.",
}, []string{}),
ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "byzantine_validators",
Help: "Number of validators who tried to double sign, partitioned by height.",
}, []string{}),
BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
Subsystem: "consensus",
Name: "block_interval_seconds",
Help: "Time between this and the last block, partitioned by height.",
Buckets: []float64{1, 2.5, 5, 10, 60},
}, []string{}),
NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "num_txs",
Help: "Number of transactions, partitioned by height.",
}, []string{}),
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{}),
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Node is the highest level interface to a full Tendermint node. // Node is the highest level interface to a full Tendermint node.
@ -126,6 +182,7 @@ func NewNode(config *cfg.Config,
clientCreator proxy.ClientCreator, clientCreator proxy.ClientCreator,
genesisDocProvider GenesisDocProvider, genesisDocProvider GenesisDocProvider,
dbProvider DBProvider, dbProvider DBProvider,
metricsProvider MetricsProvider,
logger log.Logger) (*Node, error) { logger log.Logger) (*Node, error) {
// Get BlockStore // Get BlockStore
@ -245,65 +302,9 @@ func NewNode(config *cfg.Config,
bcReactor.SetLogger(logger.With("module", "blockchain")) bcReactor.SetLogger(logger.With("module", "blockchain"))
// Make ConsensusReactor // Make ConsensusReactor
// TODO: extract to provider csMetrics := metricsProvider()
metrics := &cs.Metrics{
Height: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
Subsystem: "consensus",
Name: "height",
Help: "Height of the chain.",
}, []string{}),
Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "validators",
Help: "Number of validators who signed, partitioned by height.",
}, []string{"height"}),
MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
Name: "missing_validators",
Help: "Number of validators who did not sign, partitioned by height.",
}, []string{"height"}),
ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Subsystem: "consensus",
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(), consensusState := cs.NewConsensusState(config.Consensus, state.Copy(),
blockExec, blockStore, mempool, evidencePool, metrics) blockExec, blockStore, mempool, evidencePool, csMetrics)
consensusState.SetLogger(consensusLogger) consensusState.SetLogger(consensusLogger)
if privValidator != nil { if privValidator != nil {
consensusState.SetPrivValidator(privValidator) consensusState.SetPrivValidator(privValidator)

View File

@ -122,7 +122,9 @@ func NewTendermint(app abci.Application) *nm.Node {
papp := proxy.NewLocalClientCreator(app) papp := proxy.NewLocalClientCreator(app)
node, err := nm.NewNode(config, pv, papp, node, err := nm.NewNode(config, pv, papp,
nm.DefaultGenesisDocProviderFunc(config), nm.DefaultGenesisDocProviderFunc(config),
nm.DefaultDBProvider, logger) nm.DefaultDBProvider,
nm.DefaultMetricsProvider,
logger)
if err != nil { if err != nil {
panic(err) panic(err)
} }