Skip to content

Commit bb6b73a

Browse files
committed
Due docker environment, some of info not relevant, update metrics function
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 9c00d37 commit bb6b73a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,23 @@ async fn ax_metrics() -> (StatusCode, String) {
206206
metrics.push_str("# TYPE storage_free_space gauge\n");
207207
metrics.push_str("# HELP storage_total_space Total space on the disk\n");
208208
metrics.push_str("# TYPE storage_total_space gauge\n");
209-
let hostname = sysinfo::System::host_name().unwrap_or_else(|| "<unknown>".to_owned());
209+
let hostname = "kernelci-storage".to_string();
210210

211211
let disks = Disks::new_with_refreshed_list();
212212
for disk in disks.list() {
213+
// if mount_point is not / and not /workdir, skip it
214+
// Docker :(
215+
let mount_point = disk.mount_point().to_string_lossy();
216+
if mount_point != "/" && mount_point != "/workdir" {
217+
continue;
218+
}
213219
// name, mount_point, total_space, available_space
214220
let tag_diskname = disk.name().to_string_lossy();
215-
let tag_mount_point = disk.mount_point().to_string_lossy();
216221
let tag_total_space = disk.total_space();
217222
let tag_available_space = disk.available_space();
218223

219-
metrics.push_str(&format!("storage_free_space {{hostname=\"{}\", diskname=\"{}\", mount_point=\"{}\"}} {}\n", hostname, tag_diskname, tag_mount_point, tag_available_space));
220-
metrics.push_str(&format!("storage_total_space {{hostname=\"{}\", diskname=\"{}\", mount_point=\"{}\"}} {}\n", hostname, tag_diskname, tag_mount_point, tag_total_space));
224+
metrics.push_str(&format!("storage_free_space {{hostname=\"{}\", diskname=\"{}\", mount_point=\"{}\"}} {}\n", hostname, tag_diskname, mount_point, tag_available_space));
225+
metrics.push_str(&format!("storage_total_space {{hostname=\"{}\", diskname=\"{}\", mount_point=\"{}\"}} {}\n", hostname, tag_diskname, mount_point, tag_total_space));
221226
}
222227
(StatusCode::OK, metrics)
223228
}

0 commit comments

Comments
 (0)