diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 508ee111..4306eca3 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -84,6 +84,9 @@ pub use maintenance::*; mod network; pub use network::*; +mod node; +pub use node::*; + pub use proxmox_auth_api::types as userid; pub use proxmox_auth_api::types::{Authid, Userid}; pub use proxmox_auth_api::types::{Realm, RealmRef}; diff --git a/pbs-api-types/src/node.rs b/pbs-api-types/src/node.rs new file mode 100644 index 00000000..704215bb --- /dev/null +++ b/pbs-api-types/src/node.rs @@ -0,0 +1,100 @@ +use serde::{Deserialize, Serialize}; +use proxmox_schema::*; + +use crate::StorageStatus; + + +#[api] +#[derive(Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +/// Node memory usage counters +pub struct NodeMemoryCounters { + /// Total memory + pub total: u64, + /// Used memory + pub used: u64, + /// Free memory + 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] +#[derive(Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +/// Contains general node information such as the fingerprint` +pub struct NodeInformation { + /// The SSL Fingerprint + 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( + properties: { + memory: { + type: NodeMemoryCounters, + }, + root: { + type: StorageStatus, + }, + swap: { + type: NodeSwapCounters, + }, + loadavg: { + type: Array, + items: { + type: Number, + description: "the load", + } + }, + cpuinfo: { + type: NodeCpuInformation, + }, + info: { + type: NodeInformation, + } + }, +)] +#[derive(Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +/// The Node status +pub struct NodeStatus { + pub memory: NodeMemoryCounters, + 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. + pub cpu: f64, + /// Total IO wait since last query. + pub wait: f64, + pub cpuinfo: NodeCpuInformation, + pub info: NodeInformation, +} diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs index 4cf5e696..639d7211 100644 --- a/src/api2/node/status.rs +++ b/src/api2/node/status.rs @@ -13,17 +13,15 @@ use pbs_api_types::{ NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT, }; -use crate::api2::types::{ +use pbs_api_types::{ NodeCpuInformation, NodeInformation, NodeMemoryCounters, NodeStatus, NodeSwapCounters, }; -impl std::convert::From for NodeCpuInformation { - fn from(info: procfs::ProcFsCPUInfo) -> Self { - Self { - model: info.model, - sockets: info.sockets, - cpus: info.cpus, - } +fn procfs_to_node_cpu_info(info: procfs::ProcFsCPUInfo) -> NodeCpuInformation { + NodeCpuInformation { + model: info.model, + sockets: info.sockets, + cpus: info.cpus, } } @@ -69,7 +67,7 @@ async fn get_status( let loadavg = [loadavg.one(), loadavg.five(), loadavg.fifteen()]; let cpuinfo = procfs::read_cpuinfo()?; - let cpuinfo = cpuinfo.into(); + let cpuinfo = procfs_to_node_cpu_info(cpuinfo); let uname = nix::sys::utsname::uname()?; let kversion = format!( diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 9a65c691..afc34b30 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -1,12 +1,9 @@ //! API Type Definitions use anyhow::bail; -use serde::{Deserialize, Serialize}; use proxmox_schema::*; -use pbs_api_types::StorageStatus; - mod acme; pub use acme::*; @@ -123,101 +120,6 @@ fn test_proxmox_user_id_schema() -> Result<(), anyhow::Error> { Ok(()) } -#[api] -#[derive(Serialize, Deserialize, Default)] -#[serde(rename_all = "kebab-case")] -/// Node memory usage counters -pub struct NodeMemoryCounters { - /// Total memory - pub total: u64, - /// Used memory - pub used: u64, - /// Free memory - 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] -#[derive(Serialize, Deserialize, Default)] -#[serde(rename_all = "kebab-case")] -/// Contains general node information such as the fingerprint` -pub struct NodeInformation { - /// The SSL Fingerprint - 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( - properties: { - memory: { - type: NodeMemoryCounters, - }, - root: { - type: StorageStatus, - }, - swap: { - type: NodeSwapCounters, - }, - loadavg: { - type: Array, - items: { - type: Number, - description: "the load", - } - }, - cpuinfo: { - type: NodeCpuInformation, - }, - info: { - type: NodeInformation, - } - }, -)] -#[derive(Serialize, Deserialize, Default)] -#[serde(rename_all = "kebab-case")] -/// The Node status -pub struct NodeStatus { - pub memory: NodeMemoryCounters, - 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. - pub cpu: f64, - /// Total IO wait since last query. - pub wait: f64, - pub cpuinfo: NodeCpuInformation, - pub info: NodeInformation, -} - pub const HTTP_PROXY_SCHEMA: Schema = StringSchema::new("HTTP proxy configuration [http://][:port]") .format(&ApiStringFormat::VerifyFn(|s| {