Skip to content

Conversation

@rodrigo-o
Copy link
Collaborator

@rodrigo-o rodrigo-o commented Dec 4, 2025

Motivation

We want information about the current status of p2p peers in our node.

Description

This PR:

  • Creates a new p2p module in the metrics crate
  • Instruments established connections and disconnections for peers using the already available metrics.rs module in networking (which wasn't exposing metrics to prometheus but to logs instead)
  • Fix an issue were some disconnections weren't seen due to just reporting on the Disconnect message receive branch.
  • Add a new Peer Info rows and 5 panels
  • Updated documentation
image

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

Lines of code report

Total lines added: 160
Total lines removed: 0
Total lines changed: 160

Detailed view
+-----------------------------------------------------------+-------+------+
| File                                                      | Lines | Diff |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/api.rs                   | 53    | +5   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/mod.rs                   | 50    | +2   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/metrics/p2p.rs                   | 75    | +75  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/metrics.rs                   | 619   | +20  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/handshake.rs | 528   | +2   |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/server.rs    | 1047  | +12  |
+-----------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/p2p.rs                  | 361   | +44  |
+-----------------------------------------------------------+-------+------+

reason: DisconnectReason,
) {
self.peers.fetch_add(1, Ordering::Relaxed);
self.peers.fetch_sub(1, Ordering::Relaxed);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently we were adding peers instead of removing them before.

Comment on lines +477 to +492
if established_state.is_validated {
// If its validated the peer was connected, so we record the disconnection.
let reason = established_state
.disconnect_reason
.unwrap_or(DisconnectReason::NetworkError);
METRICS
.record_new_rlpx_conn_disconnection(
&established_state
.node
.version
.clone()
.unwrap_or("Unknown".to_string()),
reason,
)
.await;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved from the Disconnect message handling to the teardown to take into account other reasons for disconnection that were missing previously.

@rodrigo-o rodrigo-o marked this pull request as ready for review December 4, 2025 20:17
@rodrigo-o rodrigo-o requested a review from a team as a code owner December 4, 2025 20:17
Copilot AI review requested due to automatic review settings December 4, 2025 20:17
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Dec 4, 2025
Copilot finished reviewing on behalf of rodrigo-o December 4, 2025 20:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds P2P peer metrics instrumentation to expose peer connectivity data through Prometheus and Grafana dashboards. It addresses a gap in observability by tracking peer counts, client distributions, and disconnection events.

Key Changes:

  • Creates new p2p metrics module with gauges for peer counts and client distribution, plus counters for disconnections
  • Fixes a bug where disconnections weren't tracked when peers dropped without explicit Disconnect messages
  • Adds comprehensive Grafana dashboard panels with 5 visualizations for peer monitoring

Reviewed changes

Copilot reviewed 13 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/blockchain/metrics/p2p.rs New module implementing P2P metrics with peer count gauges and disconnection counters
crates/networking/p2p/metrics.rs Updates metric recording logic to properly decrement peer counts and expose to Prometheus
crates/networking/p2p/rlpx/connection/server.rs Adds disconnect reason tracking and validated flag to handle metrics in teardown
crates/networking/p2p/rlpx/p2p.rs Adds all() method and test to ensure all DisconnectReason variants are tracked
docs/developers/l1/dashboards.md Documents new Peer Info dashboard row with panel descriptions
metrics/provisioning/grafana/dashboards/common_dashboards/ethrex_l1_perf.json Adds 5 new Grafana panels for peer visualization
crates/blockchain/metrics/Cargo.toml Updates metrics feature to include prometheus dependency
cmd/ethrex/Cargo.toml Enables metrics feature for ethrex-p2p crate

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@ElFantasma ElFantasma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 😎

Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants