Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/common/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ lazy_static::lazy_static! {
&[],
default_registry()
).expect("failed to create PQ_SIGNATURE_ATTESTATION_VERIFICATION_TIME histogram vec");

// Network Metrics
pub static ref LEAN_PEER_COUNT: IntGaugeVec = register_int_gauge_vec_with_registry!(
"lean_connected_peers",
"Number of connected peers",
&[],
default_registry()
).expect("failed to create LEAN_PEER_COUNT int gauge vec");

pub static ref LEAN_CONNECTION_EVENT_TOTAL: IntCounterVec = register_int_counter_vec_with_registry!(
"lean_peer_connection_events_total",
"Number of connection events",
&[],
default_registry()
).expect("failed to create LEAN_CONNECTION_EVENT_TOTAL int counter vec");

pub static ref LEAN_DISCONNECTION_EVENT_TOTAL: IntCounterVec = register_int_counter_vec_with_registry!(
"lean_peer_disconnection_events_total",
"Number of disconnection events",
&[],
default_registry()
).expect("failed to create LEAN_DISCONNECTION_EVENT_TOTAL int counter vec");
}

/// Set the value of a gauge metric
Expand Down
1 change: 1 addition & 0 deletions crates/networking/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ream-discv5.workspace = true
ream-events-beacon.workspace = true
ream-executor.workspace = true
ream-light-client.workspace = true
ream-metrics.workspace = true
ream-network-spec.workspace = true
ream-network-state-lean.workspace = true
ream-peer.workspace = true
Expand Down
17 changes: 17 additions & 0 deletions crates/networking/p2p/src/network/lean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ use libp2p::{
use libp2p_identity::{Keypair, PeerId, secp256k1};
use ream_chain_lean::{messages::LeanChainServiceMessage, p2p_request::LeanP2PRequest};
use ream_executor::ReamExecutor;
use ream_metrics::{
LEAN_CONNECTION_EVENT_TOTAL, LEAN_DISCONNECTION_EVENT_TOTAL, LEAN_PEER_COUNT,
inc_int_counter_vec, set_int_gauge_vec,
};
use ream_network_spec::networks::{Devnet, lean_network_spec};
use ream_network_state_lean::{NetworkState, cached_peer::CachedPeer};
use ream_peer::{ConnectionState, Direction};
Expand Down Expand Up @@ -225,6 +229,7 @@ impl LeanNetworkService {

pub async fn start(&mut self, bootnodes: Bootnodes) -> anyhow::Result<()> {
info!("LeanNetworkService started");
set_int_gauge_vec(&LEAN_PEER_COUNT, 0, &[]);

self.connect_to_bootnodes(bootnodes.to_multiaddrs_lean())
.await;
Expand Down Expand Up @@ -375,6 +380,12 @@ impl LeanNetworkService {
ConnectionState::Connected,
direction,
);
set_int_gauge_vec(
&LEAN_PEER_COUNT,
self.network_state.connected_peers() as i64,
&[],
);
inc_int_counter_vec(&LEAN_CONNECTION_EVENT_TOTAL, &[]);

info!(
"Connected to peer: {peer_id:?} {:?}",
Expand All @@ -395,6 +406,12 @@ impl LeanNetworkService {
ConnectionState::Disconnected,
direction,
);
set_int_gauge_vec(
&LEAN_PEER_COUNT,
self.network_state.connected_peers() as i64,
&[],
);
inc_int_counter_vec(&LEAN_DISCONNECTION_EVENT_TOTAL, &[]);

info!("Disconnected from peer: {peer_id:?}");
Some(ReamNetworkEvent::PeerDisconnected(peer_id))
Expand Down