From fff278a4945f0d1d4e4b406959c65e692a6ce370 Mon Sep 17 00:00:00 2001 From: "(on company time)" <_@_> Date: Fri, 29 Jul 2022 17:02:25 -0500 Subject: [PATCH] report VmRSS in metrics --- crates/ptth_relay/src/scraper_api.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/ptth_relay/src/scraper_api.rs b/crates/ptth_relay/src/scraper_api.rs index 3bf6512..299ecde 100644 --- a/crates/ptth_relay/src/scraper_api.rs +++ b/crates/ptth_relay/src/scraper_api.rs @@ -216,10 +216,23 @@ async fn metrics ( -> Result , RequestError> { let mut s = String::with_capacity (4 * 1_024); + s.push_str ("# HELP forty_two Forty-two\n"); s.push_str ("# TYPE forty_two counter\n"); s.push_str ("forty_two 42\n"); + #[cfg (target_os = "linux")] + { + if let Some (rss) = tokio::fs::read_to_string ("/proc/self/status").await + .ok () + .and_then (|s| get_rss_from_status (s.as_str ())) + { + s.push_str ("# HELP relay_vm_rss VmRSS of the relay process, in kB\n"); + s.push_str ("# TYPE relay_vm_rss gauge\n"); + s.push_str (format! ("relay_vm_rss {}\n", rss).as_str ()); + } + } + Ok (Response::builder () .body (Body::from (s))?) }