diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-19 23:13:49 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-24 23:33:33 +0800 |
commit | 821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc (patch) | |
tree | c60bba0fc7d0d71895a52e4bd7e3a7c2cb4f536c /eth/fetcher/fetcher.go | |
parent | 22c7ce0162f2d14a7340e00e93697780c91d2087 (diff) | |
download | dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar.gz dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar.bz2 dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar.lz dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar.xz dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.tar.zst dexon-821e01b0139eee9bfab9647e4ac1f2d6f1fb01bc.zip |
cmd/geth, eth/fetcher: initial metrics support
Conflicts:
cmd/geth/admin.go
Diffstat (limited to 'eth/fetcher/fetcher.go')
-rw-r--r-- | eth/fetcher/fetcher.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index 90a202235..a9f4227c4 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -7,6 +7,8 @@ import ( "math/rand" "time" + "github.com/rcrowley/go-metrics" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/logger" @@ -96,6 +98,11 @@ type Fetcher struct { // Testing hooks fetchingHook func([]common.Hash) // Method to call upon starting a block fetch importedHook func(*types.Block) // Method to call upon successful block import + + // Runtime metrics + announceStats metrics.Meter + broadcastStats metrics.Meter + discardStats metrics.Meter } // New creates a block fetcher to retrieve blocks based on hash announcements. @@ -118,6 +125,9 @@ func New(getBlock blockRetrievalFn, validateBlock blockValidatorFn, broadcastBlo chainHeight: chainHeight, insertChain: insertChain, dropPeer: dropPeer, + announceStats: metrics.GetOrRegisterMeter("eth/Announced Blocks", metrics.DefaultRegistry), + broadcastStats: metrics.GetOrRegisterMeter("eth/Propagated Blocks", metrics.DefaultRegistry), + discardStats: metrics.GetOrRegisterMeter("eth/Discarded Blocks", metrics.DefaultRegistry), } } @@ -229,6 +239,8 @@ func (f *Fetcher) loop() { case notification := <-f.notify: // A block was announced, make sure the peer isn't DOSing us + f.announceStats.Mark(1) + count := f.announces[notification.origin] + 1 if count > hashLimit { glog.V(logger.Debug).Infof("Peer %s: exceeded outstanding announces (%d)", notification.origin, hashLimit) @@ -246,6 +258,7 @@ func (f *Fetcher) loop() { case op := <-f.inject: // A direct block insertion was requested, try and fill any pending gaps + f.broadcastStats.Mark(1) f.enqueue(op.origin, op.block) case hash := <-f.done: @@ -364,6 +377,7 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) { // Discard any past or too distant blocks if dist := int64(block.NumberU64()) - int64(f.chainHeight()); dist < -maxUncleDist || dist > maxQueueDist { glog.V(logger.Debug).Infof("Peer %s: discarded block #%d [%x], distance %d", peer, block.NumberU64(), hash.Bytes()[:4], dist) + f.discardStats.Mark(1) return } // Schedule the block for future importing |