From 5002e6bc9f2448898df3d47f167f522c9e663a7e Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Sat, 11 Mar 2023 17:24:16 +0100 Subject: [PATCH] Add scaphandre mem metrics --- src/exporters/elastic.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/exporters/elastic.rs b/src/exporters/elastic.rs index 5b1df5fd..3e2d3701 100644 --- a/src/exporters/elastic.rs +++ b/src/exporters/elastic.rs @@ -122,6 +122,9 @@ const ES_INDEX_NAME: &str = "scaphandre"; pub struct ScaphandreData { pub scaphandre_version: String, pub scaphandre_cpu_usage_percentage: Option, + pub scaphandre_mem_total_program_size: Option, + pub scaphrandre_mem_resident_set_size: Option, + pub scaphandre_mem_shared_resident_size: Option, } impl ElasticExporter { @@ -153,6 +156,10 @@ impl ElasticExporter { .body(ScaphandreData { scaphandre_version: get_scaphandre_version(), scaphandre_cpu_usage_percentage: self.get_scaphandre_cpu_usage_percentage(), + scaphandre_mem_total_program_size: self.get_scaphandre_mem_total_program_size(), + scaphrandre_mem_resident_set_size: self.get_scaphandre_mem_resident_set_size(), + scaphandre_mem_shared_resident_size: self + .get_scaphandre_mem_shared_resident_size(), }) .send() .await @@ -176,6 +183,27 @@ impl ElasticExporter { .ok() } + fn get_scaphandre_mem_total_program_size(&self) -> Option { + let statm_value = procfs::process::Process::myself().ok()?.statm().ok()?; + let page_size = procfs::page_size().ok()?; + + Some(statm_value.size * page_size as u64) + } + + fn get_scaphandre_mem_resident_set_size(&self) -> Option { + let statm_value = procfs::process::Process::myself().ok()?.statm().ok()?; + let page_size = procfs::page_size().ok()?; + + Some(statm_value.resident * page_size as u64) + } + + fn get_scaphandre_mem_shared_resident_size(&self) -> Option { + let statm_value = procfs::process::Process::myself().ok()?.statm().ok()?; + let page_size = procfs::page_size().ok()?; + + Some(statm_value.shared * page_size as u64) + } + async fn ensure_index(&self, client: &Elasticsearch) -> Result<(), Error> { let index_exist_resp = client .indices()