1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
//! Disk stats for FreeBSD.
use std::io;
use serde::Deserialize;
use super::{keep_disk_entry, DiskHarvest, IoHarvest};
use crate::{app::data_harvester::DataCollector, data_harvester::deserialize_xo, utils::error};
#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case")]
struct StorageSystemInformation {
filesystem: Vec<FileSystem>,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
struct FileSystem {
name: String,
total_blocks: u64,
used_blocks: u64,
available_blocks: u64,
mounted_on: String,
}
pub fn get_io_usage() -> error::Result<IoHarvest> {
let io_harvest = get_disk_info().map(|storage_system_information| {
storage_system_information
.filesystem
.into_iter()
.map(|disk| (disk.name, None))
.collect()
})?;
Ok(io_harvest)
}
pub fn get_disk_usage(collector: &DataCollector) -> error::Result<Vec<DiskHarvest>> {
let disk_filter = &collector.filters.disk_filter;
let mount_filter = &collector.filters.mount_filter;
let vec_disks: Vec<DiskHarvest> = get_disk_info().map(|storage_system_information| {
storage_system_information
.filesystem
.into_iter()
.filter_map(|disk| {
if keep_disk_entry(&disk.name, &disk.mounted_on, disk_filter, mount_filter) {
Some(DiskHarvest {
free_space: Some(disk.available_blocks * 1024),
used_space: Some(disk.used_blocks * 1024),
total_space: Some(disk.total_blocks * 1024),
mount_point: disk.mounted_on,
name: disk.name,
})
} else {
None
}
})
.collect()
})?;
Ok(vec_disks)
}
fn get_disk_info() -> io::Result<StorageSystemInformation> {
// TODO: Ideally we don't have to shell out to a new program.
let output = std::process::Command::new("df")
.args(["--libxo", "json", "-k", "-t", "ufs,msdosfs,zfs"])
.output()?;
deserialize_xo("storage-system-information", &output.stdout)
}
|