Add basic metrics to libp2p

This commit is contained in:
Paul Hauner 2019-08-12 14:16:20 +10:00
parent 0b4a8893a4
commit cac0e5c832
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
4 changed files with 26 additions and 0 deletions

View File

@ -26,3 +26,5 @@ smallvec = "0.6.10"
fnv = "1.0.6"
unsigned-varint = "0.2.2"
bytes = "0.4.12"
lazy_static = "1.3.0"
lighthouse_metrics = { path = "../../eth2/utils/lighthouse_metrics" }

View File

@ -1,3 +1,4 @@
use crate::metrics;
use crate::{error, NetworkConfig};
/// This manages the discovery and management of peers.
///
@ -158,10 +159,12 @@ where
}
fn inject_connected(&mut self, peer_id: PeerId, _endpoint: ConnectedPoint) {
metrics::inc_counter(&metrics::PEER_CONNECT_COUNT);
self.connected_peers.insert(peer_id);
}
fn inject_disconnected(&mut self, peer_id: &PeerId, _endpoint: ConnectedPoint) {
metrics::inc_counter(&metrics::PEER_DISCONNECT_COUNT);
self.connected_peers.remove(peer_id);
}
@ -217,6 +220,7 @@ where
}
Discv5Event::SocketUpdated(socket) => {
info!(self.log, "Address updated"; "IP" => format!("{}",socket.ip()));
metrics::inc_counter(&metrics::ADDRESS_UPDATE_COUNT);
let mut address = Multiaddr::from(socket.ip());
address.push(Protocol::Tcp(self.tcp_port));
let enr = self.discovery.local_enr();

View File

@ -2,10 +2,14 @@
/// all required libp2p functionality.
///
/// This crate builds and manages the libp2p services required by the beacon node.
#[macro_use]
extern crate lazy_static;
pub mod behaviour;
mod config;
mod discovery;
pub mod error;
mod metrics;
pub mod rpc;
mod service;

View File

@ -0,0 +1,16 @@
pub use lighthouse_metrics::*;
lazy_static! {
pub static ref ADDRESS_UPDATE_COUNT: Result<IntCounter> = try_create_int_counter(
"libp2p_address_update_count",
"Count of libp2p socked updated events (when our view of our IP address has changed)"
);
pub static ref PEER_CONNECT_COUNT: Result<IntCounter> = try_create_int_counter(
"libp2p_peer_connect_count",
"Count of libp2p peer connect events (not the current number of connected peers)"
);
pub static ref PEER_DISCONNECT_COUNT: Result<IntCounter> = try_create_int_counter(
"libp2p_peer_disconnect_count",
"Count of libp2p peer disconnect events"
);
}