let disk_usage return StorageStatus and use it for datastores/nodes
disk_usage returned the same values as defined in StorageStatus, so simply use that with that we can replace the logic of the datastore status with that function and also use it for root disk usage of the nodes Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
da84cc52f4
commit
33070956af
|
@ -382,25 +382,8 @@ pub fn status(
|
|||
_info: &ApiMethod,
|
||||
_rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<StorageStatus, Error> {
|
||||
|
||||
let datastore = DataStore::lookup_datastore(&store)?;
|
||||
|
||||
let base_path = datastore.base_path();
|
||||
|
||||
let mut stat: libc::statfs64 = unsafe { std::mem::zeroed() };
|
||||
|
||||
use nix::NixPath;
|
||||
|
||||
let res = base_path.with_nix_path(|cstr| unsafe { libc::statfs64(cstr.as_ptr(), &mut stat) })?;
|
||||
nix::errno::Errno::result(res)?;
|
||||
|
||||
let bsize = stat.f_bsize as u64;
|
||||
|
||||
Ok(StorageStatus {
|
||||
total: stat.f_blocks*bsize,
|
||||
used: (stat.f_blocks-stat.f_bfree)*bsize,
|
||||
avail: stat.f_bavail*bsize,
|
||||
})
|
||||
crate::tools::disks::disk_usage(&datastore.base_path())
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::process::Command;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{Error, format_err, bail};
|
||||
use serde_json::{json, Value};
|
||||
|
@ -60,6 +61,7 @@ fn get_usage(
|
|||
|
||||
let meminfo: procfs::ProcFsMemInfo = procfs::read_meminfo()?;
|
||||
let kstat: procfs::ProcFsStat = procfs::read_proc_stat()?;
|
||||
let disk_usage = crate::tools::disks::disk_usage(Path::new("/"))?;
|
||||
|
||||
Ok(json!({
|
||||
"memory": {
|
||||
|
@ -68,6 +70,11 @@ fn get_usage(
|
|||
"free": meminfo.memfree,
|
||||
},
|
||||
"cpu": kstat.cpu,
|
||||
"root": {
|
||||
"total": disk_usage.total,
|
||||
"used": disk_usage.used,
|
||||
"free": disk_usage.avail,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -711,11 +711,11 @@ async fn generate_host_stats(save: bool) {
|
|||
fn gather_disk_stats(disk_manager: Arc<DiskManage>, path: &Path, rrd_prefix: &str, save: bool) {
|
||||
|
||||
match proxmox_backup::tools::disks::disk_usage(path) {
|
||||
Ok((total, used, _avail)) => {
|
||||
Ok(status) => {
|
||||
let rrd_key = format!("{}/total", rrd_prefix);
|
||||
rrd_update_gauge(&rrd_key, total as f64, save);
|
||||
rrd_update_gauge(&rrd_key, status.total as f64, save);
|
||||
let rrd_key = format!("{}/used", rrd_prefix);
|
||||
rrd_update_gauge(&rrd_key, used as f64, save);
|
||||
rrd_update_gauge(&rrd_key, status.used as f64, save);
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("read disk_usage on {:?} failed - {}", path, err);
|
||||
|
|
|
@ -19,7 +19,7 @@ use proxmox::sys::linux::procfs::{MountInfo, mountinfo::Device};
|
|||
use proxmox::{io_bail, io_format_err};
|
||||
use proxmox::api::api;
|
||||
|
||||
use crate::api2::types::BLOCKDEVICE_NAME_REGEX;
|
||||
use crate::api2::types::{BLOCKDEVICE_NAME_REGEX, StorageStatus};
|
||||
|
||||
mod zfs;
|
||||
pub use zfs::*;
|
||||
|
@ -511,7 +511,7 @@ impl Disk {
|
|||
}
|
||||
|
||||
/// Returns disk usage information (total, used, avail)
|
||||
pub fn disk_usage(path: &std::path::Path) -> Result<(u64, u64, u64), Error> {
|
||||
pub fn disk_usage(path: &std::path::Path) -> Result<StorageStatus, Error> {
|
||||
|
||||
let mut stat: libc::statfs64 = unsafe { std::mem::zeroed() };
|
||||
|
||||
|
@ -522,7 +522,11 @@ pub fn disk_usage(path: &std::path::Path) -> Result<(u64, u64, u64), Error> {
|
|||
|
||||
let bsize = stat.f_bsize as u64;
|
||||
|
||||
Ok((stat.f_blocks*bsize, (stat.f_blocks-stat.f_bfree)*bsize, stat.f_bavail*bsize))
|
||||
Ok(StorageStatus{
|
||||
total: stat.f_blocks*bsize,
|
||||
used: (stat.f_blocks-stat.f_bfree)*bsize,
|
||||
avail: stat.f_bavail*bsize,
|
||||
})
|
||||
}
|
||||
|
||||
#[api()]
|
||||
|
|
Loading…
Reference in New Issue