This commit is contained in:
parent
38d9c74db5
commit
03e954560e
4 changed files with 57 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.swp
|
*.swp
|
||||||
/.direnv
|
/.direnv
|
||||||
|
Packet.lib
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1544,6 +1544,7 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -51,7 +51,10 @@ tokio.workspace = true
|
||||||
tokio-stream.workspace = true
|
tokio-stream.workspace = true
|
||||||
opentelemetry.workspace = true
|
opentelemetry.workspace = true
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
winapi = { version = "0.3.9", features = ["fileapi", "impl-default"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
kubernetes-discovery = [ "kube", "k8s-openapi", "schemars" ]
|
kubernetes-discovery = ["kube", "k8s-openapi", "schemars"]
|
||||||
consul-discovery = [ "reqwest", "err-derive" ]
|
consul-discovery = ["reqwest", "err-derive"]
|
||||||
system-libs = [ "sodiumoxide/use-pkg-config" ]
|
system-libs = ["sodiumoxide/use-pkg-config"]
|
||||||
|
|
|
@ -817,22 +817,58 @@ impl NodeStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
fn update_disk_usage(&mut self, meta_dir: &Path, data_dir: &DataDirEnum) {
|
fn update_disk_usage(&mut self, meta_dir: &Path, data_dir: &DataDirEnum) {
|
||||||
#[cfg(unix)]
|
use winapi::um::fileapi::GetDiskFreeSpaceExA;
|
||||||
let mount_avail = {
|
use winapi::um::winnt::ULARGE_INTEGER;
|
||||||
use nix::sys::statvfs::statvfs;
|
|
||||||
|path: &Path| match statvfs(path) {
|
let mount_avail = |path: &Path| -> Option<(u64, u64)> {
|
||||||
Ok(x) => {
|
let mut path = path.to_path_buf();
|
||||||
let avail = x.blocks_available() as u64 * x.fragment_size() as u64;
|
path.push(""); // Ensure trailing slash
|
||||||
let total = x.blocks() as u64 * x.fragment_size() as u64;
|
|
||||||
Some((x.filesystem_id(), avail, total))
|
let mut a: ULARGE_INTEGER = Default::default();
|
||||||
}
|
let mut total: ULARGE_INTEGER = Default::default();
|
||||||
Err(_) => None,
|
let mut free: ULARGE_INTEGER = Default::default();
|
||||||
|
|
||||||
|
let path_ptr = path.as_os_str().as_encoded_bytes().as_ptr();
|
||||||
|
let result = unsafe {
|
||||||
|
GetDiskFreeSpaceExA(path_ptr as *const i8, &mut a, &mut total, &mut free)
|
||||||
|
};
|
||||||
|
|
||||||
|
if result == 0 {
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let free = unsafe { *free.QuadPart() };
|
||||||
|
let total = unsafe { *total.QuadPart() };
|
||||||
|
|
||||||
|
Some((free, total))
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(windows)]
|
self.meta_disk_avail = mount_avail(meta_dir);
|
||||||
let mount_avail = |_path: &Path| None::<(u64, _, _)>;
|
self.data_disk_avail = match data_dir {
|
||||||
|
DataDirEnum::Single(path_buf) => mount_avail(path_buf),
|
||||||
|
|
||||||
|
// TODO: THIS IS WRONG!! Does not take into account multiple dirs on the same partition
|
||||||
|
// Will have to deduplicate by the filesystem mount path
|
||||||
|
DataDirEnum::Multiple(dirs) => dirs
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|dir| mount_avail(&dir.path))
|
||||||
|
.reduce(|(a1, b1), (a2, b2)| (a1 + a2, b1 + b2)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn update_disk_usage(&mut self, meta_dir: &Path, data_dir: &DataDirEnum) {
|
||||||
|
use nix::sys::statvfs::statvfs;
|
||||||
|
let mount_avail = |path: &Path| match statvfs(path) {
|
||||||
|
Ok(x) => {
|
||||||
|
let avail = x.blocks_available() as u64 * x.fragment_size() as u64;
|
||||||
|
let total = x.blocks() as u64 * x.fragment_size() as u64;
|
||||||
|
Some((x.filesystem_id(), avail, total))
|
||||||
|
}
|
||||||
|
Err(_) => None,
|
||||||
|
};
|
||||||
|
|
||||||
self.meta_disk_avail = mount_avail(meta_dir).map(|(_, a, t)| (a, t));
|
self.meta_disk_avail = mount_avail(meta_dir).map(|(_, a, t)| (a, t));
|
||||||
self.data_disk_avail = match data_dir {
|
self.data_disk_avail = match data_dir {
|
||||||
|
|
Loading…
Reference in a new issue