aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhaoping-ku <haoping.ku@cobinhood.com>2019-01-18 14:43:41 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commite095c638a46b467a1487a6f236ec7dd86555f424 (patch)
tree40f2cdf0d3040bb65f429aeb898b643b70a2e454
parent88b3ad43fb7f7d69672a9ce42992b01e17ffbb5f (diff)
downloaddexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar.gz
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar.bz2
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar.lz
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar.xz
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.tar.zst
dexon-e095c638a46b467a1487a6f236ec7dd86555f424.zip
dex: add block number gauge (#140)
-rw-r--r--dex/handler.go43
1 files changed, 25 insertions, 18 deletions
diff --git a/dex/handler.go b/dex/handler.go
index a3fbf2ba9..a745bbfc7 100644
--- a/dex/handler.go
+++ b/dex/handler.go
@@ -59,6 +59,7 @@ import (
"github.com/dexon-foundation/dexon/ethdb"
"github.com/dexon-foundation/dexon/event"
"github.com/dexon-foundation/dexon/log"
+ "github.com/dexon-foundation/dexon/metrics"
"github.com/dexon-foundation/dexon/p2p"
"github.com/dexon-foundation/dexon/p2p/enode"
"github.com/dexon-foundation/dexon/p2p/enr"
@@ -142,6 +143,9 @@ type ProtocolManager struct {
finalizedBlockCh chan core.NewFinalizedBlockEvent
finalizedBlockSub event.Subscription
+
+ // metrics
+ blockNumberGauge metrics.Gauge
}
// NewProtocolManager returns a new Ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
@@ -154,23 +158,24 @@ func NewProtocolManager(
tab := newNodeTable()
// Create the protocol manager with the base fields
manager := &ProtocolManager{
- networkID: networkID,
- dMoment: dMoment,
- eventMux: mux,
- txpool: txpool,
- nodeTable: tab,
- gov: gov,
- blockchain: blockchain,
- cache: newCache(5120, dexDB.NewDatabase(chaindb)),
- chainconfig: config,
- newPeerCh: make(chan *peer),
- noMorePeers: make(chan struct{}),
- txsyncCh: make(chan *txsync),
- recordsyncCh: make(chan *recordsync),
- quitSync: make(chan struct{}),
- receiveCh: make(chan interface{}, 1024),
- isBlockProposer: isBlockProposer,
- app: app,
+ networkID: networkID,
+ dMoment: dMoment,
+ eventMux: mux,
+ txpool: txpool,
+ nodeTable: tab,
+ gov: gov,
+ blockchain: blockchain,
+ cache: newCache(5120, dexDB.NewDatabase(chaindb)),
+ chainconfig: config,
+ newPeerCh: make(chan *peer),
+ noMorePeers: make(chan struct{}),
+ txsyncCh: make(chan *txsync),
+ recordsyncCh: make(chan *recordsync),
+ quitSync: make(chan struct{}),
+ receiveCh: make(chan interface{}, 1024),
+ isBlockProposer: isBlockProposer,
+ app: app,
+ blockNumberGauge: metrics.GetOrRegisterGauge("dex/blocknumber", nil),
}
// Figure out whether to allow fast sync or not
@@ -1182,7 +1187,9 @@ func (pm *ProtocolManager) peerSetLoop() {
for {
select {
- case <-pm.chainHeadCh:
+ case event := <-pm.chainHeadCh:
+ pm.blockNumberGauge.Update(int64(event.Block.NumberU64()))
+
if !pm.isBlockProposer {
break
}