This displays CPU utilization across all nodes like "Summary" of
"Resources" in "Datacenter" of PVE web ui.

Signed-off-by: Dominik Rusovac <[email protected]>
---

 changes since v1:
 * sum up products of cpu and maxcpu per node; and divide by total maxcpu

 src/pages/page_dashboard.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/pages/page_dashboard.rs b/src/pages/page_dashboard.rs
index f637c63..ac8e3e7 100644
--- a/src/pages/page_dashboard.rs
+++ b/src/pages/page_dashboard.rs
@@ -100,7 +100,7 @@ impl PvePageDashboard {
 
                 for node in node_list.iter() {
                     if let (Some(node_cpu), Some(node_maxcpu)) = (node.cpu, 
node.maxcpu) {
-                        cpu += node_cpu;
+                        cpu += node_cpu * node_maxcpu as f64;
                         maxcpu += node_maxcpu;
                     }
                     if let (Some(node_mem), Some(node_maxmem)) = (node.mem, 
node.maxmem) {
@@ -109,7 +109,7 @@ impl PvePageDashboard {
                     }
                 }
 
-                let cpu_percentage = if maxcpu == 0 {
+                let cpu_proportion = if maxcpu == 0 {
                     0.0
                 } else {
                     (cpu as f32) / (maxcpu as f32)
@@ -125,9 +125,9 @@ impl PvePageDashboard {
 
                 tiles.push(
                     icon_list_tile(Fa::new("cpu"), tr!("CPU"), (), 
()).with_child(list_tile_usage(
-                        format!("{:.2}", cpu),
+                        format!("{:.2}", cpu_proportion * 100.0),
                         maxcpu.to_string(),
-                        cpu_percentage,
+                        cpu_proportion,
                     )),
                 );
 
-- 
2.47.3




Reply via email to