Skip to content

p2p: Add metrics for tracking p2p modules#510

Merged
tungng98 merged 2 commits intoBuildOnViction:pre-releasefrom
c98tristan:feat/add-p2p-metrics
Mar 20, 2025
Merged

p2p: Add metrics for tracking p2p modules#510
tungng98 merged 2 commits intoBuildOnViction:pre-releasefrom
c98tristan:feat/add-p2p-metrics

Conversation

@c98tristan
Copy link
Copy Markdown
Contributor

This pull request includes several changes to the metrics and p2p packages to enhance functionality and improve code quality. The most important changes include the addition of increment and decrement methods to the Gauge interface, updates to the p2p package for better metrics tracking, and minor code corrections.

Enhancements to metrics package:

  • Added Inc and Dec methods to the Gauge interface and implemented these methods for GaugeSnapshot, NilGauge, and StandardGauge types. (metrics/gauge.go) [1] [2] [3] [4] [5]

Updates to p2p package:

  • Introduced new constants for ingress and egress meter names and updated existing metrics to use these constants. (p2p/metrics.go)
  • Added activePeerGauge to track the number of active peers and updated connection handling to increment and decrement this gauge appropriately. (p2p/metrics.go) [1] [2]
  • Enhanced message handling to include metering for ingress and egress traffic. (p2p/message.go, p2p/peer.go, p2p/rlpx.go) [1] [2] [3] [4] [5] [6] [7]
	// ingressMeterName is the prefix of the per-packet inbound metrics.
	ingressMeterName = "p2p/ingress"

	// egressMeterName is the prefix of the per-packet outbound metrics.
	egressMeterName = "p2p/egress"
	ingressConnectMeter = metrics.NewRegisteredMeter("p2p/serves", nil)
	ingressTrafficMeter = metrics.NewRegisteredMeter(ingressMeterName, nil)
	egressConnectMeter  = metrics.NewRegisteredMeter("p2p/dials", nil)
	egressTrafficMeter  = metrics.NewRegisteredMeter(egressMeterName, nil)
	activePeerGauge     = metrics.NewRegisteredGauge("p2p/peers", nil)

New p2p metrics:

# TYPE p2p_dials gauge
p2p_dials 2

# TYPE p2p_egress gauge
p2p_egress 678287

# TYPE p2p_egress_eth_63_0x00 gauge
p2p_egress_eth_63_0x00 610

# TYPE p2p_egress_eth_63_0x02 gauge
p2p_egress_eth_63_0x02 165096

# TYPE p2p_egress_eth_63_0x03 gauge
p2p_egress_eth_63_0x03 362

# TYPE p2p_egress_eth_63_0x04 gauge
p2p_egress_eth_63_0x04 9446

# TYPE p2p_egress_eth_63_0x05 gauge
p2p_egress_eth_63_0x05 1434

# TYPE p2p_egress_eth_63_0x06 gauge
p2p_egress_eth_63_0x06 7970

# TYPE p2p_egress_eth_63_0x07 gauge
p2p_egress_eth_63_0x07 376172

# TYPE p2p_ingress gauge
p2p_ingress 709796

# TYPE p2p_ingress_eth_63_0x00 gauge
p2p_ingress_eth_63_0x00 0

# TYPE p2p_ingress_eth_63_0x00_packets gauge
p2p_ingress_eth_63_0x00_packets 8

# TYPE p2p_ingress_eth_63_0x02 gauge
p2p_ingress_eth_63_0x02 0

# TYPE p2p_ingress_eth_63_0x02_packets gauge
p2p_ingress_eth_63_0x02_packets 1300

# TYPE p2p_ingress_eth_63_0x03 gauge
p2p_ingress_eth_63_0x03 0

# TYPE p2p_ingress_eth_63_0x03_packets gauge
p2p_ingress_eth_63_0x03_packets 20

# TYPE p2p_ingress_eth_63_0x04 gauge
p2p_ingress_eth_63_0x04 0

# TYPE p2p_ingress_eth_63_0x04_packets gauge
p2p_ingress_eth_63_0x04_packets 25

# TYPE p2p_ingress_eth_63_0x05 gauge
p2p_ingress_eth_63_0x05 0

# TYPE p2p_ingress_eth_63_0x05_packets gauge
p2p_ingress_eth_63_0x05_packets 16

# TYPE p2p_ingress_eth_63_0x06 gauge
p2p_ingress_eth_63_0x06 0

# TYPE p2p_ingress_eth_63_0x06_packets gauge
p2p_ingress_eth_63_0x06_packets 19

# TYPE p2p_ingress_eth_63_0x07 gauge
p2p_ingress_eth_63_0x07 0

# TYPE p2p_ingress_eth_63_0x07_packets gauge
p2p_ingress_eth_63_0x07_packets 482

# TYPE p2p_peers gauge
p2p_peers 6

# TYPE p2p_serves gauge
p2p_serves 6

Code corrections:

  • Fixed a typo in a comment within the p2p/dial.go file. (p2p/dial.go)

Reference:

@tungng98 tungng98 merged commit bb3d26e into BuildOnViction:pre-release Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants