Add metrics for beacon block propagation (#2173)

## Issue Addressed

NA

## Proposed Changes

Adds some metrics to track delays regarding:

- LH processing of blocks
- delays receiving blocks from other nodes.

## Additional Info

NA
This commit is contained in:
Paul Hauner
2021-02-04 05:33:56 +00:00
parent de193c95d3
commit ff35fbb121
6 changed files with 78 additions and 22 deletions

View File

@@ -252,14 +252,8 @@ pub fn start_timer(histogram: &Result<Histogram>) -> Option<HistogramTimer> {
/// Starts a timer on `vec` with the given `name`.
pub fn observe_timer_vec(vec: &Result<HistogramVec>, name: &[&str], duration: Duration) {
// This conversion was taken from here:
//
// https://docs.rs/prometheus/0.5.0/src/prometheus/histogram.rs.html#550-555
let nanos = f64::from(duration.subsec_nanos()) / 1e9;
let secs = duration.as_secs() as f64 + nanos;
if let Some(h) = get_histogram(vec, name) {
h.observe(secs)
h.observe(duration_to_f64(duration))
}
}
@@ -330,3 +324,17 @@ pub fn observe(histogram: &Result<Histogram>, value: f64) {
histogram.observe(value);
}
}
pub fn observe_duration(histogram: &Result<Histogram>, duration: Duration) {
if let Ok(histogram) = histogram {
histogram.observe(duration_to_f64(duration))
}
}
fn duration_to_f64(duration: Duration) -> f64 {
// This conversion was taken from here:
//
// https://docs.rs/prometheus/0.5.0/src/prometheus/histogram.rs.html#550-555
let nanos = f64::from(duration.subsec_nanos()) / 1e9;
duration.as_secs() as f64 + nanos
}