From 7165598b7fe3346ece3420bf808d14391106295a Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 12 Aug 2019 18:19:50 +1000 Subject: [PATCH] Add lighthouse_metrics gather fn --- beacon_node/rest_api/src/metrics.rs | 16 +++++++++------- eth2/utils/lighthouse_metrics/src/lib.rs | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/beacon_node/rest_api/src/metrics.rs b/beacon_node/rest_api/src/metrics.rs index f0ccef5f8..064359337 100644 --- a/beacon_node/rest_api/src/metrics.rs +++ b/beacon_node/rest_api/src/metrics.rs @@ -46,20 +46,22 @@ pub fn get_prometheus(req: Request) -> ApiR // - Statically updated: things which are only updated at the time of the scrape (used where we // can avoid cluttering up code with metrics calls). // - // The `prometheus` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`) which - // keeps the state of all the metrics. Dynamically updated things will already be up-to-date in - // the registry (because they update themselves) however statically updated things need to be - // "scraped". + // The `lighthouse_metrics` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`) + // which keeps the state of all the metrics. Dynamically updated things will already be + // up-to-date in the registry (because they update themselves) however statically updated + // things need to be "scraped". // // We proceed by, first updating all the static metrics using `scrape_for_metrics(..)`. Then, - // using `prometheus::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into a - // string that can be returned via HTTP. + // using `lighthouse_metrics::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into + // a string that can be returned via HTTP. slot_clock::scrape_for_metrics::(&beacon_chain.slot_clock); store::scrape_for_metrics(&db_path); beacon_chain::scrape_for_metrics(&beacon_chain); - encoder.encode(&prometheus::gather(), &mut buffer).unwrap(); + encoder + .encode(&lighthouse_metrics::gather(), &mut buffer) + .unwrap(); String::from_utf8(buffer) .map(|string| success_response(Body::from(string))) diff --git a/eth2/utils/lighthouse_metrics/src/lib.rs b/eth2/utils/lighthouse_metrics/src/lib.rs index a8656d017..c9e66e971 100644 --- a/eth2/utils/lighthouse_metrics/src/lib.rs +++ b/eth2/utils/lighthouse_metrics/src/lib.rs @@ -2,6 +2,10 @@ use prometheus::{HistogramOpts, HistogramTimer, Opts}; pub use prometheus::{Histogram, IntCounter, IntGauge, Result}; +pub fn gather() -> Vec { + prometheus::gather() +} + pub fn try_create_int_counter(name: &str, help: &str) -> Result { let opts = Opts::new(name, help); let counter = IntCounter::with_opts(opts)?;