Skip to content

Commit e901c21

Browse files
committed
Add scaphandre cpu usage percentage
1 parent c3b57c8 commit e901c21

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/exporters/elastic.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const ES_INDEX_NAME: &str = "scaphandre";
121121
#[derive(Debug, Serialize, Deserialize, PartialEq)]
122122
pub struct ScaphandreData {
123123
pub scaphandre_version: String,
124+
pub scaphandre_cpu_usage_percentage: Option<u32>,
124125
}
125126

126127
impl ElasticExporter {
@@ -151,6 +152,7 @@ impl ElasticExporter {
151152
))
152153
.body(ScaphandreData {
153154
scaphandre_version: get_scaphandre_version(),
155+
scaphandre_cpu_usage_percentage: self.get_scaphandre_cpu_usage_percentage(),
154156
})
155157
.send()
156158
.await
@@ -166,6 +168,14 @@ impl ElasticExporter {
166168
}
167169
}
168170

171+
fn get_scaphandre_cpu_usage_percentage(&self) -> Option<u32> {
172+
self.topology
173+
.get_process_cpu_consumption_percentage(procfs::process::Process::myself().ok()?.pid())?
174+
.value
175+
.parse::<u32>()
176+
.ok()
177+
}
178+
169179
async fn ensure_index(&self, client: &Elasticsearch) -> Result<(), Error> {
170180
let index_exist_resp = client
171181
.indices()

0 commit comments

Comments
 (0)