From 071e30cc530f2c89cd9bc07bffc07e9cb1a595aa Mon Sep 17 00:00:00 2001 From: anastasia Date: Wed, 27 Oct 2021 20:37:11 +0300 Subject: [PATCH] Expose TENANT_THREADS_COUNT metric to observe number of currently active checkpointer and GC threads --- pageserver/src/tenant_threads.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pageserver/src/tenant_threads.rs b/pageserver/src/tenant_threads.rs index 3dc824180b..d7d06fdef8 100644 --- a/pageserver/src/tenant_threads.rs +++ b/pageserver/src/tenant_threads.rs @@ -11,6 +11,7 @@ use std::sync::Mutex; use std::thread::JoinHandle; use std::time::Duration; use tracing::*; +use zenith_metrics::{register_int_gauge_vec, IntGaugeVec}; use zenith_utils::zid::ZTenantId; struct TenantHandleEntry { @@ -25,6 +26,15 @@ lazy_static! { Mutex::new(HashMap::new()); } +lazy_static! { + static ref TENANT_THREADS_COUNT: IntGaugeVec = register_int_gauge_vec!( + "tenant_threads_count", + "Number of live tenant threads", + &["tenant_thread_type"] + ) + .expect("failed to define a metric"); +} + pub fn start_tenant_threads(conf: &'static PageServerConf, tenantid: ZTenantId) { //ensure that old threads are stopeed wait_for_tenant_threads_to_stop(tenantid); @@ -69,6 +79,12 @@ pub fn wait_for_tenant_threads_to_stop(tenantid: ZTenantId) { /// Checkpointer thread's main loop /// fn checkpoint_loop(tenantid: ZTenantId, conf: &'static PageServerConf) -> Result<()> { + let gauge = TENANT_THREADS_COUNT.with_label_values(&["checkpointer"]); + gauge.inc(); + scopeguard::defer! { + gauge.dec(); + } + loop { if tenant_mgr::get_tenant_state(tenantid) != TenantState::Active { break; @@ -95,6 +111,12 @@ fn checkpoint_loop(tenantid: ZTenantId, conf: &'static PageServerConf) -> Result /// GC thread's main loop /// fn gc_loop(tenantid: ZTenantId, conf: &'static PageServerConf) -> Result<()> { + let gauge = TENANT_THREADS_COUNT.with_label_values(&["gc"]); + gauge.inc(); + scopeguard::defer! { + gauge.dec(); + } + loop { if tenant_mgr::get_tenant_state(tenantid) != TenantState::Active { break;