-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_info_graph.rs
More file actions
66 lines (52 loc) · 1.63 KB
/
cpu_info_graph.rs
File metadata and controls
66 lines (52 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use sysinfo::{System, SystemExt, CpuExt, DiskExt, NetworkExt, BatteryExt};
use std::{thread, time::Duration};
fn main()
{
let mut system = System::new_all();
loop {
system.refresh_all();
print!("\x1B[2J\x1B[1;1H");
println!("=======*MINI SYSTEM MONITOR*=======\n");
//RAM
println!("RAM: Total {} MB | Used {} MB",
system.total_memory() / 1024,
system.used_memory() / 1024);
//CPU
println!("\nCPU:");
for (i, cpu) in system.cpus().iter().enumerate()
{
println!(" Core {}: {:.2}%", i, cpu.cpu_usage());
}
// Disks
println!("\nDisks:");
for disk in system.disks()
{
println!("{:?}: {} / {} GB free",
disk.name(),
disk.available_space() / 1_000_000_000,
disk.total_space() / 1_000_000_000
);
}
//Network
println!("\nNetwork:");
for (name, data) in system.networks()
{
println!("{}: received {} KB | transmitted {} KB",
name,
data.received() / 1024,
data.transmitted() / 1024
);
}
//Battery
if let Some(battery) = system.batteries().next()
{
println!("\nBattery: {:.0}% ({:?})",
battery.percentage() * 100.0,
battery.state()
);
}
println!("\nUptime: {} seconds", system.uptime());
println!("\n(Refreshing every 1 second... Press Ctrl+C to exit)");
thread::sleep(Duration::from_secs(1));
}
}