p2p metric, make height and totalTxs gauges

This commit is contained in:
Anton Kaliaev
2018-06-20 12:38:45 +04:00
parent 0cb50c05fc
commit 19699d644f
8 changed files with 125 additions and 89 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ func TestByzantine(t *testing.T) {
switches := make([]*p2p.Switch, N)
p2pLogger := logger.With("module", "p2p")
for i := 0; i < N; i++ {
switches[i] = p2p.NewSwitch(config.P2P)
switches[i] = p2p.NewSwitch(config.P2P, p2p.NopMetrics())
switches[i].SetLogger(p2pLogger.With("validator", i))
}
+19 -11
View File
@@ -6,7 +6,8 @@ import "github.com/go-kit/kit/metrics/discard"
// Metrics contains metrics exposed by this package.
// see MetricsProvider for descriptions.
type Metrics struct {
Height metrics.Counter
Height metrics.Gauge
Rounds metrics.Gauge
Validators metrics.Gauge
@@ -18,22 +19,29 @@ type Metrics struct {
BlockIntervalSeconds metrics.Histogram
NumTxs metrics.Gauge
TotalTxs metrics.Counter
NumTxs metrics.Gauge
BlockSizeBytes metrics.Gauge
TotalTxs metrics.Gauge
}
// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
Height: discard.NewCounter(),
Validators: discard.NewGauge(),
MissingValidators: discard.NewGauge(),
ByzantineValidators: discard.NewGauge(),
Height: discard.NewGauge(),
Rounds: discard.NewGauge(),
Validators: discard.NewGauge(),
ValidatorsPower: discard.NewGauge(),
MissingValidators: discard.NewGauge(),
MissingValidatorsPower: discard.NewGauge(),
ByzantineValidators: discard.NewGauge(),
ByzantineValidatorsPower: discard.NewGauge(),
BlockIntervalSeconds: discard.NewHistogram(),
NumTxs: discard.NewGauge(),
TotalTxs: discard.NewCounter(),
BlockSizeBytes: discard.NewGauge(),
NumTxs: discard.NewGauge(),
BlockSizeBytes: discard.NewGauge(),
TotalTxs: discard.NewGauge(),
}
}
+4 -4
View File
@@ -391,7 +391,7 @@ func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *t
// internal functions for managing the state
func (cs *ConsensusState) updateHeight(height int64) {
cs.metrics.Height.Add(float64(height - cs.Height))
cs.metrics.Height.Set(float64(height))
cs.Height = height
}
@@ -697,7 +697,6 @@ func (cs *ConsensusState) enterNewRound(height int64, round int) {
}
logger.Info(cmn.Fmt("enterNewRound(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step))
cs.metrics.Rounds.Set(float64(round))
// Increment validators if necessary
validators := cs.Validators
@@ -724,6 +723,7 @@ func (cs *ConsensusState) enterNewRound(height int64, round int) {
cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
cs.eventBus.PublishEventNewRound(cs.RoundStateEvent())
cs.metrics.Rounds.Set(float64(round))
// Wait for txs to be available in the mempool
// before we enterPropose in round 0. If the last block changed the app hash,
@@ -1282,6 +1282,7 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
fail.Fail() // XXX
// must be called before we update state
cs.recordMetrics(height, block)
// NewHeightStep!
@@ -1332,9 +1333,8 @@ func (cs *ConsensusState) recordMetrics(height int64, block *types.Block) {
}
cs.metrics.NumTxs.Set(float64(block.NumTxs))
cs.metrics.TotalTxs.Add(float64(block.NumTxs))
cs.metrics.BlockSizeBytes.Set(float64(block.Size()))
cs.metrics.TotalTxs.Set(float64(block.TotalTxs))
}
//-----------------------------------------------------------------------------