From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH yew-comp 8/8] add `node_info` helper to render a consistent view of the NodeStatus
Date: Tue, 23 Sep 2025 11:51:11 +0200 [thread overview]
Message-ID: <20250923095124.1679038-9-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250923095124.1679038-1-d.csapak@proxmox.com>
since we want this for the pve and pbs NodeStatus, we introduce a small
enum type that can hold a reference to either and dynamically extract the
information we need.
That way we can easily use the helper for both PVE and PBS node panels.
The content itself should be the same as the one we have in the native
PVE and PBS interface, minus the subscription info.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
Cargo.toml | 3 +
src/lib.rs | 3 +
src/node_info.rs | 222 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 228 insertions(+)
create mode 100644 src/node_info.rs
diff --git a/Cargo.toml b/Cargo.toml
index 11680c7..d6002a8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -82,6 +82,9 @@ proxmox-access-control = "1.1"
proxmox-dns-api = { version = "1", optional = true }
proxmox-network-api = { version = "1", optional = true }
+pve-api-types = "8"
+pbs-api-types = "1"
+
[features]
default = []
apt = [
diff --git a/src/lib.rs b/src/lib.rs
index ca34e67..492326a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -80,6 +80,9 @@ pub use loadable_component::{
LoadableComponent, LoadableComponentContext, LoadableComponentLink, LoadableComponentMaster,
};
+mod node_info;
+pub use node_info::{node_info, NodeStatus};
+
mod notes_view;
pub use notes_view::{NotesView, NotesWithDigest, ProxmoxNotesView};
diff --git a/src/node_info.rs b/src/node_info.rs
new file mode 100644
index 0000000..19a1ada
--- /dev/null
+++ b/src/node_info.rs
@@ -0,0 +1,222 @@
+use proxmox_human_byte::HumanByte;
+use pwt::{prelude::*, widget::Container};
+
+use crate::{MeterLabel, StatusRow};
+
+/// Type that holds either a PVE NodeStatus or a PBS NodeStatus
+pub enum NodeStatus<'a> {
+ Pve(&'a pve_api_types::NodeStatus),
+ Pbs(&'a pbs_api_types::NodeStatus),
+}
+
+impl<'a> From<&'a pve_api_types::NodeStatus> for NodeStatus<'a> {
+ fn from(value: &'a pve_api_types::NodeStatus) -> Self {
+ NodeStatus::Pve(value)
+ }
+}
+
+impl<'a> From<&'a pbs_api_types::NodeStatus> for NodeStatus<'a> {
+ fn from(value: &'a pbs_api_types::NodeStatus) -> Self {
+ NodeStatus::Pbs(value)
+ }
+}
+
+/// Renders the NodeInfo panel content
+// TODO: add repository status
+// NOTE: if we need internal state or the tree get's too big, we should convert this
+// into a proper component
+pub fn node_info(data: Option<NodeStatus>) -> Container {
+ let (cpu, cpus_total) = match data {
+ Some(NodeStatus::Pve(node_status)) => (node_status.cpu, node_status.cpuinfo.cpus as u64),
+ Some(NodeStatus::Pbs(node_status)) => (node_status.cpu, node_status.cpuinfo.cpus as u64),
+ None => (0.0, 1),
+ };
+
+ let wait = match data {
+ Some(NodeStatus::Pve(node_status)) => node_status
+ .additional_properties
+ .get("wait")
+ .and_then(|wait| wait.as_f64())
+ .unwrap_or_default(),
+ Some(NodeStatus::Pbs(node_status)) => node_status.wait,
+ None => 0.0,
+ };
+
+ let (memory_used, memory_total) = match data {
+ Some(NodeStatus::Pve(node_status)) => (
+ node_status.memory.used as u64,
+ node_status.memory.total as u64,
+ ),
+ Some(NodeStatus::Pbs(node_status)) => (node_status.memory.used, node_status.memory.total),
+ None => (0, 1),
+ };
+
+ let loadavg = match data {
+ Some(NodeStatus::Pve(node_status)) => node_status.loadavg.join(" "),
+ Some(NodeStatus::Pbs(node_status)) => format!(
+ "{:.2} {:.2} {:.2}",
+ node_status.loadavg[0], node_status.loadavg[1], node_status.loadavg[2]
+ ),
+ None => tr!("N/A"),
+ };
+
+ let (root_used, root_total) = match data {
+ Some(NodeStatus::Pve(node_status)) => (
+ node_status.rootfs.used as u64,
+ node_status.rootfs.total as u64,
+ ),
+ Some(NodeStatus::Pbs(node_status)) => (node_status.root.used, node_status.root.total),
+ None => (0, 1),
+ };
+
+ let (swap_used, swap_total) = match data {
+ Some(NodeStatus::Pve(node_status)) => {
+ if let Some(swap) = node_status
+ .additional_properties
+ .get("swap")
+ .and_then(|swap| swap.as_object())
+ {
+ let used = swap
+ .get("used")
+ .and_then(|used| used.as_u64())
+ .unwrap_or_default();
+ let total = swap
+ .get("total")
+ .and_then(|used| used.as_u64())
+ .unwrap_or(0);
+ (used, total)
+ } else {
+ (0, 0)
+ }
+ }
+ Some(NodeStatus::Pbs(node_status)) => (node_status.swap.used, node_status.swap.total),
+ None => (0, 1),
+ };
+
+ let (model, sockets) = match data {
+ Some(NodeStatus::Pve(node_status)) => (
+ node_status.cpuinfo.model.clone(),
+ node_status.cpuinfo.sockets as u64,
+ ),
+ Some(NodeStatus::Pbs(node_status)) => (
+ node_status.cpuinfo.model.clone(),
+ node_status.cpuinfo.sockets as u64,
+ ),
+ None => (String::new(), 1),
+ };
+
+ let version = match data {
+ Some(NodeStatus::Pve(node_status)) => Some(node_status.pveversion.clone()),
+ _ => None,
+ };
+
+ let (k_sysname, k_release, k_version) = match data {
+ Some(NodeStatus::Pve(node_status)) => (
+ node_status.current_kernel.sysname.clone(),
+ node_status.current_kernel.release.clone(),
+ node_status.current_kernel.version.clone(),
+ ),
+ Some(NodeStatus::Pbs(node_status)) => (
+ node_status.current_kernel.sysname.clone(),
+ node_status.current_kernel.release.clone(),
+ node_status.current_kernel.version.clone(),
+ ),
+ None => (String::new(), String::new(), String::new()),
+ };
+
+ Container::new()
+ .class("pwt-d-grid pwt-gap-2 pwt-align-items-center")
+ .style("grid-template-columns", "1fr 20px 1fr")
+ .style("height", "fit-content")
+ .padding(4)
+ .with_child(
+ MeterLabel::with_zero_optimum(tr!("CPU Usage"))
+ .animated(true)
+ .icon_class("fa fa-fw fa-cpu")
+ .value(cpu as f32)
+ .status(format!("{:.2}% of {} CPU(s)", cpu * 100.0, cpus_total)),
+ )
+ .with_child(
+ MeterLabel::with_zero_optimum(tr!("IO delay"))
+ .animated(true)
+ .style("grid-column", "3")
+ .icon_class("fa fa-fw fa-clock-o")
+ .value(wait as f32),
+ )
+ .with_child(Container::new().padding(2).style("grid-column", "1/-1"))
+ .with_child({
+ let fraction = ((memory_used as f64) / (memory_total as f64)) as f32;
+ MeterLabel::with_zero_optimum(tr!("RAM Usage"))
+ .animated(true)
+ .icon_class("fa fa-fw fa-memory")
+ .value(fraction)
+ .status(format!(
+ "{:.2}% ({} of {})",
+ fraction * 100.0,
+ HumanByte::from(memory_used),
+ HumanByte::from(memory_total),
+ ))
+ })
+ .with_child(
+ StatusRow::new(tr!("Load Average"))
+ .icon_class("fa fa-fw fa-tasks")
+ .status(loadavg)
+ .style("grid-column", "3"),
+ )
+ .with_child({
+ let fraction = ((root_used as f64) / (root_total as f64)) as f32;
+ MeterLabel::with_zero_optimum(tr!("HD space (root)"))
+ .animated(true)
+ .icon_class("fa fa-fw fa-hdd-o")
+ .value(fraction)
+ .status(format!(
+ "{:.2}% ({} of {})",
+ fraction * 100.0,
+ HumanByte::new_decimal(root_used as f64),
+ HumanByte::new_decimal(root_total as f64),
+ ))
+ })
+ .with_child({
+ let (fraction, status) = if swap_total > 0 {
+ let fraction = ((swap_used as f64) / (swap_total as f64)) as f32;
+ let status = format!(
+ "{:.2}% ({} of {})",
+ fraction * 100.0,
+ HumanByte::from(swap_used),
+ HumanByte::from(swap_total),
+ );
+ (Some(fraction), status)
+ } else {
+ (None, tr!("N/A"))
+ };
+ MeterLabel::with_zero_optimum(tr!("SWAP usage"))
+ .animated(true)
+ .style("grid-column", "3")
+ .icon_class("fa fa-fw fa-refresh")
+ .value(fraction)
+ .animated(true)
+ .status(status)
+ })
+ .with_child(Container::new().padding(2).style("grid-column", "1/-1"))
+ .with_child({
+ let cpu_model_text = format!(
+ "{} x {} ({})",
+ cpus_total,
+ model,
+ ngettext!("1 Socket", "{n} Sockets", sockets),
+ );
+ StatusRow::new(tr!("CPU(s)"))
+ .style("grid-column", "1/-1")
+ .status(cpu_model_text)
+ })
+ .with_optional_child(version.map(|version| {
+ StatusRow::new(tr!("Version"))
+ .style("grid-column", "1/-1")
+ .status(version)
+ }))
+ .with_child(
+ StatusRow::new(tr!("Kernel Version"))
+ .style("grid-column", "1/-1")
+ .status(format!("{} {} {}", k_sysname, k_release, k_version)),
+ )
+}
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-09-23 9:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 9:51 [pdm-devel] [PATCH datacenter-manager/yew-comp 00/10] status row/node status cleanup + refactor Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 1/8] status: impl conversion to classes Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 2/8] status row: add option to add the icon on the right side Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 3/8] meter label: make value optional Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 4/8] meter label: use `StatusRow` for text row Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 5/8] meter label: align the status row with baseline Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 6/8] meter label: add `animated` property Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH yew-comp 7/8] meter label: add option to align the icon on the right Dominik Csapak
2025-09-23 9:51 ` Dominik Csapak [this message]
2025-09-23 9:51 ` [pdm-devel] [PATCH datacenter-manager 1/2] ui: pve: node: use `node_info` helper from yew-comp Dominik Csapak
2025-09-23 9:51 ` [pdm-devel] [PATCH datacenter-manager 2/2] ui: rework status row/meter helpers Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250923095124.1679038-9-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.