mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-19 01:20:39 +00:00
eth/dropper: add metrics
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
75c8ee1439
commit
1647f51eed
1 changed files with 13 additions and 0 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
)
|
||||
|
||||
|
|
@ -43,6 +44,13 @@ const (
|
|||
syncCheckInterval = 60 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
// droppedInbound is the number of inbound peers dropped
|
||||
droppedInbound = metrics.NewRegisteredMeter("eth/dropper/inbound", nil)
|
||||
// droppedOutbound is the number of outbound peers dropped
|
||||
droppedOutbound = metrics.NewRegisteredMeter("eth/dropper/outbound", nil)
|
||||
)
|
||||
|
||||
// dropper monitors the state of the peer pool and makes changes as follows:
|
||||
// - during sync the Downloader handles peer connections, so dropper is disabled
|
||||
// - if not syncing and the peer count is close to the limit, it drops peers
|
||||
|
|
@ -128,6 +136,11 @@ func (cm *dropper) dropRandomPeer() bool {
|
|||
p := droppable[mrand.Intn(len(droppable))]
|
||||
log.Debug("Dropping random peer", "id", p.ID(), "duration", common.PrettyDuration(p.Lifetime()), "inbound", p.Inbound(), "peercountbefore", len(peers))
|
||||
p.Disconnect(p2p.DiscTooManyPeers)
|
||||
if p.Inbound() {
|
||||
droppedInbound.Mark(1)
|
||||
} else {
|
||||
droppedOutbound.Mark(1)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
|
|||
Loading…
Reference in a new issue