From 5609feb3b3de876c5cc8ec4cbb904c6b460e59bc Mon Sep 17 00:00:00 2001 From: Morgan Mccauley Date: Fri, 23 Feb 2024 14:29:28 +1300 Subject: [PATCH] feat: Expose `LOGS_COUNT` metric --- block-streamer/src/main.rs | 1 + block-streamer/src/metrics.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/block-streamer/src/main.rs b/block-streamer/src/main.rs index 04097df9e..1ca9beca8 100644 --- a/block-streamer/src/main.rs +++ b/block-streamer/src/main.rs @@ -16,6 +16,7 @@ mod test_utils; async fn main() -> anyhow::Result<()> { tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer()) + .with(metrics::LogCounter) .with(tracing_subscriber::EnvFilter::from_default_env()) .init(); diff --git a/block-streamer/src/metrics.rs b/block-streamer/src/metrics.rs index 9ce3729fa..0c691f17e 100644 --- a/block-streamer/src/metrics.rs +++ b/block-streamer/src/metrics.rs @@ -3,6 +3,8 @@ use lazy_static::lazy_static; use prometheus::{ register_int_counter_vec, register_int_gauge_vec, Encoder, IntCounterVec, IntGaugeVec, }; +use tracing_subscriber::layer::Context; +use tracing_subscriber::Layer; lazy_static! { pub static ref LAST_PROCESSED_BLOCK: IntGaugeVec = register_int_gauge_vec!( @@ -23,6 +25,25 @@ lazy_static! { &["indexer"] ) .unwrap(); + pub static ref LOGS_COUNT: IntCounterVec = register_int_counter_vec!( + "queryapi_block_streamer_logs_count", + "Number of messages logged", + &["level"] + ) + .unwrap(); +} + +pub struct LogCounter; + +impl Layer for LogCounter +where + S: tracing::Subscriber, +{ + fn on_event(&self, event: &tracing::Event, _ctx: Context) { + LOGS_COUNT + .with_label_values(&[event.metadata().level().as_str()]) + .inc(); + } } #[get("/metrics")]