api2/node/status: extend node status

to be more on par with pve

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-04-19 13:02:03 +02:00 committed by Thomas Lamprecht
parent eb70464839
commit 398636b61c
2 changed files with 86 additions and 0 deletions

View File

@ -12,6 +12,16 @@ use crate::api2::types::*;
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT}; use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT};
use crate::tools::cert::CertInfo; use crate::tools::cert::CertInfo;
impl std::convert::From<procfs::ProcFsCPUInfo> for NodeCpuInformation {
fn from(info: procfs::ProcFsCPUInfo) -> Self {
Self {
model: info.model,
sockets: info.sockets,
cpus: info.cpus,
}
}
}
#[api( #[api(
input: { input: {
properties: { properties: {
@ -40,13 +50,40 @@ fn get_status(
free: meminfo.memfree, free: meminfo.memfree,
}; };
let swap = NodeSwapCounters {
total: meminfo.swaptotal,
used: meminfo.swapused,
free: meminfo.swapfree,
};
let kstat: procfs::ProcFsStat = procfs::read_proc_stat()?; let kstat: procfs::ProcFsStat = procfs::read_proc_stat()?;
let cpu = kstat.cpu; let cpu = kstat.cpu;
let wait = kstat.iowait_percent;
let loadavg = procfs::Loadavg::read()?;
let loadavg = [loadavg.one(), loadavg.five(), loadavg.fifteen()];
let cpuinfo = procfs::read_cpuinfo()?;
let cpuinfo = cpuinfo.into();
let uname = nix::sys::utsname::uname();
let kversion = format!(
"{} {} {}",
uname.sysname(),
uname.release(),
uname.version()
);
Ok(NodeStatus { Ok(NodeStatus {
memory, memory,
swap,
root: crate::tools::disks::disk_usage(Path::new("/"))?, root: crate::tools::disks::disk_usage(Path::new("/"))?,
uptime: procfs::read_proc_uptime()?.0 as u64,
loadavg,
kversion,
cpuinfo,
cpu, cpu,
wait,
info: NodeInformation { info: NodeInformation {
fingerprint: CertInfo::new()?.fingerprint()?, fingerprint: CertInfo::new()?.fingerprint()?,
}, },

View File

@ -1520,6 +1520,19 @@ pub struct NodeMemoryCounters {
pub free: u64, pub free: u64,
} }
#[api]
#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
/// Node swap usage counters
pub struct NodeSwapCounters {
/// Total swap
pub total: u64,
/// Used swap
pub used: u64,
/// Free swap
pub free: u64,
}
#[api] #[api]
#[derive(Serialize,Deserialize,Default)] #[derive(Serialize,Deserialize,Default)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
@ -1529,6 +1542,19 @@ pub struct NodeInformation {
pub fingerprint: String, pub fingerprint: String,
} }
#[api]
#[derive(Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
/// Information about the CPU
pub struct NodeCpuInformation {
/// The CPU model
pub model: String,
/// The number of CPU sockets
pub sockets: usize,
/// The number of CPU cores (incl. threads)
pub cpus: usize,
}
#[api( #[api(
properties: { properties: {
memory: { memory: {
@ -1537,6 +1563,19 @@ pub struct NodeInformation {
root: { root: {
type: StorageStatus, type: StorageStatus,
}, },
swap: {
type: NodeSwapCounters,
},
loadavg: {
type: Array,
items: {
type: Number,
description: "the load",
}
},
cpuinfo: {
type: NodeCpuInformation,
},
info: { info: {
type: NodeInformation, type: NodeInformation,
} }
@ -1548,7 +1587,17 @@ pub struct NodeInformation {
pub struct NodeStatus { pub struct NodeStatus {
pub memory: NodeMemoryCounters, pub memory: NodeMemoryCounters,
pub root: StorageStatus, pub root: StorageStatus,
pub swap: NodeSwapCounters,
/// The current uptime of the server.
pub uptime: u64,
/// Load for 1, 5 and 15 minutes.
pub loadavg: [f64; 3],
/// The current kernel version.
pub kversion: String,
/// Total CPU usage since last query. /// Total CPU usage since last query.
pub cpu: f64, pub cpu: f64,
/// Total IO wait since last query.
pub wait: f64,
pub cpuinfo: NodeCpuInformation,
pub info: NodeInformation, pub info: NodeInformation,
} }