From e901c212959d946ce33deffbd5eca05f5498e443 Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Sat, 11 Mar 2023 17:07:19 +0100 Subject: [PATCH] Add scaphandre cpu usage percentage --- src/exporters/elastic.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/exporters/elastic.rs b/src/exporters/elastic.rs index 8cd0a1de..5b1df5fd 100644 --- a/src/exporters/elastic.rs +++ b/src/exporters/elastic.rs @@ -121,6 +121,7 @@ const ES_INDEX_NAME: &str = "scaphandre"; #[derive(Debug, Serialize, Deserialize, PartialEq)] pub struct ScaphandreData { pub scaphandre_version: String, + pub scaphandre_cpu_usage_percentage: Option, } impl ElasticExporter { @@ -151,6 +152,7 @@ impl ElasticExporter { )) .body(ScaphandreData { scaphandre_version: get_scaphandre_version(), + scaphandre_cpu_usage_percentage: self.get_scaphandre_cpu_usage_percentage(), }) .send() .await @@ -166,6 +168,14 @@ impl ElasticExporter { } } + fn get_scaphandre_cpu_usage_percentage(&self) -> Option { + self.topology + .get_process_cpu_consumption_percentage(procfs::process::Process::myself().ok()?.pid())? + .value + .parse::() + .ok() + } + async fn ensure_index(&self, client: &Elasticsearch) -> Result<(), Error> { let index_exist_resp = client .indices()