mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
improve libp2p connected peer metrics (#4870)
* improve libp2p connected peer metrics * separate discv5 port from libp2p for NAT open * use metric family for DISCOVERY_BYTES * Merge branch 'unstable' of https://github.com/sigp/lighthouse into improve-metrics
This commit is contained in:
@@ -244,6 +244,16 @@ pub fn inc_counter_vec(int_counter_vec: &Result<IntCounterVec>, name: &[&str]) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the `int_counter_vec` with the given `name` to the `amount`,
|
||||
/// should only be called with `ammount`s equal or above the current value
|
||||
/// as per Prometheus spec, the `counter` type should only go up.
|
||||
pub fn set_counter_vec_by(int_counter_vec: &Result<IntCounterVec>, name: &[&str], amount: u64) {
|
||||
if let Some(counter) = get_int_counter(int_counter_vec, name) {
|
||||
counter.reset();
|
||||
counter.inc_by(amount);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inc_counter_vec_by(int_counter_vec: &Result<IntCounterVec>, name: &[&str], amount: u64) {
|
||||
if let Some(counter) = get_int_counter(int_counter_vec, name) {
|
||||
counter.inc_by(amount);
|
||||
|
||||
@@ -198,6 +198,25 @@ pub fn observe_system_health_vc(
|
||||
}
|
||||
}
|
||||
|
||||
/// Observes if NAT traversal is possible.
|
||||
pub fn observe_nat() -> bool {
|
||||
let discv5_nat = lighthouse_network::metrics::get_int_gauge(
|
||||
&lighthouse_network::metrics::NAT_OPEN,
|
||||
&["discv5"],
|
||||
)
|
||||
.map(|g| g.get() == 1)
|
||||
.unwrap_or_default();
|
||||
|
||||
let libp2p_nat = lighthouse_network::metrics::get_int_gauge(
|
||||
&lighthouse_network::metrics::NAT_OPEN,
|
||||
&["libp2p"],
|
||||
)
|
||||
.map(|g| g.get() == 1)
|
||||
.unwrap_or_default();
|
||||
|
||||
discv5_nat && libp2p_nat
|
||||
}
|
||||
|
||||
/// Observes the Beacon Node system health.
|
||||
pub fn observe_system_health_bn<TSpec: EthSpec>(
|
||||
sysinfo: Arc<RwLock<System>>,
|
||||
@@ -223,11 +242,7 @@ pub fn observe_system_health_bn<TSpec: EthSpec>(
|
||||
.unwrap_or_else(|| (String::from("None"), 0, 0));
|
||||
|
||||
// Determine if the NAT is open or not.
|
||||
let nat_open = lighthouse_network::metrics::NAT_OPEN
|
||||
.as_ref()
|
||||
.map(|v| v.get())
|
||||
.unwrap_or(0)
|
||||
!= 0;
|
||||
let nat_open = observe_nat();
|
||||
|
||||
SystemHealthBN {
|
||||
system_health,
|
||||
|
||||
Reference in New Issue
Block a user