p2p: add metrics for inbound/outbound peers (#2342)

This commit is contained in:
Ng Wei Han 2024-03-29 15:06:54 +08:00 committed by GitHub
parent 3e97f827b4
commit 5d51873890
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

@ -37,7 +37,9 @@ const (
)
var (
activePeerGauge metrics.Gauge = metrics.NilGauge{}
activePeerGauge metrics.Gauge = metrics.NilGauge{}
activeInboundPeerGauge metrics.Gauge = metrics.NilGauge{}
activeOutboundPeerGauge metrics.Gauge = metrics.NilGauge{}
ingressTrafficMeter = metrics.NewRegisteredMeter("p2p/ingress", nil)
egressTrafficMeter = metrics.NewRegisteredMeter("p2p/egress", nil)
@ -74,6 +76,8 @@ func init() {
}
activePeerGauge = metrics.NewRegisteredGauge("p2p/peers", nil)
activeInboundPeerGauge = metrics.NewRegisteredGauge("p2p/peers/inbound", nil)
activeOutboundPeerGauge = metrics.NewRegisteredGauge("p2p/peers/outbound", nil)
serveMeter = metrics.NewRegisteredMeter("p2p/serves", nil)
serveSuccessMeter = metrics.NewRegisteredMeter("p2p/serves/success", nil)
dialMeter = metrics.NewRegisteredMeter("p2p/dials", nil)

@ -840,8 +840,10 @@ running:
if p.Inbound() {
inboundCount++
serveSuccessMeter.Mark(1)
activeInboundPeerGauge.Inc(1)
} else {
dialSuccessMeter.Mark(1)
activeOutboundPeerGauge.Inc(1)
}
activePeerGauge.Inc(1)
}
@ -858,6 +860,9 @@ running:
srv.dialsched.peerRemoved(pd.rw)
if pd.Inbound() {
inboundCount--
activeInboundPeerGauge.Dec(1)
} else {
activeOutboundPeerGauge.Dec(1)
}
activePeerGauge.Dec(1)
}