2020-05-28 08:07:52 +00:00
|
|
|
use anyhow::{bail, Error};
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub fn zfs_pool_stats(pool: &OsStr) -> Result<Option<BlockDevStat>, Error> {
|
|
|
|
|
|
|
|
let mut path = PathBuf::from("/proc/spl/kstat/zfs");
|
|
|
|
path.push(pool);
|
|
|
|
path.push("io");
|
|
|
|
|
|
|
|
let text = match proxmox::tools::fs::file_read_optional_string(&path)? {
|
|
|
|
Some(text) => text,
|
|
|
|
None => { return Ok(None); }
|
|
|
|
};
|
|
|
|
|
|
|
|
let lines: Vec<&str> = text.lines().collect();
|
|
|
|
|
|
|
|
if lines.len() < 3 {
|
|
|
|
bail!("unable to parse {:?} - got less than 3 lines", path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/openzfs/zfs/blob/master/lib/libspl/include/sys/kstat.h#L578
|
|
|
|
// nread nwritten reads writes wtime wlentime wupdate rtime rlentime rupdate wcnt rcnt
|
|
|
|
// Note: w -> wait (wtime -> wait time)
|
|
|
|
// Note: r -> run (rtime -> run time)
|
|
|
|
// All times are nanoseconds
|
|
|
|
let stat: Vec<u64> = lines[2].split_ascii_whitespace().map(|s| {
|
|
|
|
u64::from_str_radix(s, 10).unwrap_or(0)
|
|
|
|
}).collect();
|
|
|
|
|
2020-05-28 09:45:34 +00:00
|
|
|
let ticks = (stat[4] + stat[7])/1_000_000; // convert to milisec
|
2020-05-28 08:07:52 +00:00
|
|
|
|
|
|
|
let stat = BlockDevStat {
|
|
|
|
read_sectors: stat[0]>>9,
|
|
|
|
write_sectors: stat[1]>>9,
|
|
|
|
read_ios: stat[2],
|
|
|
|
write_ios: stat[3],
|
2020-05-28 17:11:37 +00:00
|
|
|
io_ticks: ticks,
|
2020-05-28 08:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Some(stat))
|
|
|
|
}
|