Skip to content
Open
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
10 changes: 10 additions & 0 deletions beacon_node/lighthouse_network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ lazy_static! {
"Count of libp2p peers currently connected via QUIC"
);

pub static ref IP4_PEERS_CONNECTED: Result<IntGauge> = try_create_int_gauge(
"libp2p_ipv4_peers",
"Count of libp2p peers currently connected over IPv4"
);

pub static ref IP6_PEERS_CONNECTED: Result<IntGauge> = try_create_int_gauge(
"libp2p_ipv6_peers",
"Count of libp2p peers currently connected over IPv6"
);

pub static ref PEER_CONNECT_EVENT_COUNT: Result<IntCounter> = try_create_int_counter(
"libp2p_peer_connect_event_total",
"Count of libp2p peer connect events (not the current number of connected peers)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::net::IpAddr;
use std::task::{Context, Poll};

use futures::StreamExt;
use libp2p::core::{multiaddr, ConnectedPoint};
use libp2p::core::multiaddr::Protocol;
use libp2p::core::ConnectedPoint;
use libp2p::identity::PeerId;
use libp2p::swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
use libp2p::swarm::dial_opts::{DialOpts, PeerCondition};
Expand Down Expand Up @@ -168,8 +169,8 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
) -> Result<(), ConnectionDenied> {
// get the IP address to verify it's not banned.
let ip = match remote_addr.iter().next() {
Some(libp2p::multiaddr::Protocol::Ip6(ip)) => IpAddr::V6(ip),
Some(libp2p::multiaddr::Protocol::Ip4(ip)) => IpAddr::V4(ip),
Some(Protocol::Ip6(ip)) => IpAddr::V6(ip),
Some(Protocol::Ip4(ip)) => IpAddr::V4(ip),
_ => {
return Err(ConnectionDenied::new(format!(
"Connection to peer rejected: invalid multiaddr: {remote_addr}"
Expand Down Expand Up @@ -245,18 +246,22 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
// increment prometheus metrics
if self.metrics_enabled {
let remote_addr = endpoint.get_remote_address();
match remote_addr.iter().find(|proto| {
matches!(
proto,
multiaddr::Protocol::QuicV1 | multiaddr::Protocol::Tcp(_)
)
}) {
Some(multiaddr::Protocol::QuicV1) => {
match remote_addr
.iter()
.find(|proto| matches!(proto, Protocol::QuicV1 | Protocol::Tcp(_)))
{
Some(Protocol::QuicV1) => {
metrics::inc_gauge(&metrics::QUIC_PEERS_CONNECTED);
}
Some(multiaddr::Protocol::Tcp(_)) => {
Some(Protocol::Tcp(_)) => {
metrics::inc_gauge(&metrics::TCP_PEERS_CONNECTED);
}
Some(Protocol::Ip4(_) | Protocol::Dns(_) | Protocol::Dns4(_)) => {
metrics::inc_gauge(&metrics::IP4_PEERS_CONNECTED);
}
Some(Protocol::Ip6(_) | Protocol::Dns6(_)) => {
metrics::inc_gauge(&metrics::IP6_PEERS_CONNECTED);
}
Some(_) => unreachable!(),
None => {
error!(self.log, "Connection established via unknown transport"; "addr" => %remote_addr)
Expand Down Expand Up @@ -333,18 +338,22 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
let remote_addr = endpoint.get_remote_address();
// Update the prometheus metrics
if self.metrics_enabled {
match remote_addr.iter().find(|proto| {
matches!(
proto,
multiaddr::Protocol::QuicV1 | multiaddr::Protocol::Tcp(_)
)
}) {
Some(multiaddr::Protocol::QuicV1) => {
match remote_addr
.iter()
.find(|proto| matches!(proto, Protocol::QuicV1 | Protocol::Tcp(_)))
{
Some(Protocol::QuicV1) => {
metrics::dec_gauge(&metrics::QUIC_PEERS_CONNECTED);
}
Some(multiaddr::Protocol::Tcp(_)) => {
Some(Protocol::Tcp(_)) => {
metrics::dec_gauge(&metrics::TCP_PEERS_CONNECTED);
}
Some(Protocol::Ip4(_) | Protocol::Dns(_) | Protocol::Dns4(_)) => {
metrics::dec_gauge(&metrics::IP4_PEERS_CONNECTED);
}
Some(Protocol::Ip6(_) | Protocol::Dns6(_)) => {
metrics::dec_gauge(&metrics::IP6_PEERS_CONNECTED);
}
// If it's an unknown protocol we already logged when connection was established.
_ => {}
};
Expand Down