Skip to content

Commit

Permalink
p2p: add inbound and outbound peers metric (#29424)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann authored Apr 2, 2024
1 parent a83e576 commit dfb3d46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -65,6 +67,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)
Expand Down
5 changes: 5 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,10 @@ running:
if p.Inbound() {
inboundCount++
serveSuccessMeter.Mark(1)
activeInboundPeerGauge.Inc(1)
} else {
dialSuccessMeter.Mark(1)
activeOutboundPeerGauge.Inc(1)
}
activePeerGauge.Inc(1)
}
Expand All @@ -786,6 +788,9 @@ running:
srv.dialsched.peerRemoved(pd.rw)
if pd.Inbound() {
inboundCount--
activeInboundPeerGauge.Dec(1)
} else {
activeOutboundPeerGauge.Dec(1)
}
activePeerGauge.Dec(1)
}
Expand Down

0 comments on commit dfb3d46

Please sign in to comment.