Skip to content

Commit

Permalink
Add scaphandre mem metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
papey committed Mar 11, 2023
1 parent e901c21 commit 5002e6b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/exporters/elastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ const ES_INDEX_NAME: &str = "scaphandre";
pub struct ScaphandreData {
pub scaphandre_version: String,
pub scaphandre_cpu_usage_percentage: Option<u32>,
pub scaphandre_mem_total_program_size: Option<u64>,
pub scaphrandre_mem_resident_set_size: Option<u64>,
pub scaphandre_mem_shared_resident_size: Option<u64>,
}

impl ElasticExporter {
Expand Down Expand Up @@ -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
Expand All @@ -176,6 +183,27 @@ impl ElasticExporter {
.ok()
}

fn get_scaphandre_mem_total_program_size(&self) -> Option<u64> {
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<u64> {
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<u64> {
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()
Expand Down

0 comments on commit 5002e6b

Please sign in to comment.