Skip to content

Commit

Permalink
Add scaphandre cpu usage percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
papey committed Mar 11, 2023
1 parent c3b57c8 commit e901c21
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/exporters/elastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
}

impl ElasticExporter {
Expand Down Expand Up @@ -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
Expand All @@ -166,6 +168,14 @@ impl ElasticExporter {
}
}

fn get_scaphandre_cpu_usage_percentage(&self) -> Option<u32> {
self.topology
.get_process_cpu_consumption_percentage(procfs::process::Process::myself().ok()?.pid())?
.value
.parse::<u32>()
.ok()
}

async fn ensure_index(&self, client: &Elasticsearch) -> Result<(), Error> {
let index_exist_resp = client
.indices()
Expand Down

0 comments on commit e901c21

Please sign in to comment.