use geneos_toolkit::prelude::*;
struct Process {
id: u32,
name: String,
cpu: f32,
mem: u64,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let processes = vec![
Process {
id: 101,
name: "nginx".to_string(),
cpu: 1.2,
mem: 1024,
},
Process {
id: 102,
name: "postgres".to_string(),
cpu: 4.5,
mem: 4096,
},
Process {
id: 103,
name: "redis".to_string(),
cpu: 0.8,
mem: 512,
},
];
let mut builder = Dataview::builder()
.set_row_header("pid")
.add_headline("source", "system_monitor");
for proc in processes {
let row = Row::new(proc.id)
.add_cell("name", proc.name)
.add_cell("cpu", format!("{:.1}%", proc.cpu))
.add_cell("memory", format!("{}MB", proc.mem));
builder = builder.add_row(row);
}
print_result_and_exit(builder.build());
}