Struct systemstat::data::DelayedMeasurement
source · pub struct DelayedMeasurement<T> { /* private fields */ }
Expand description
A wrapper for a measurement that takes time.
Time should pass between getting the object and calling .done() on it.
Implementations§
source§impl<T> DelayedMeasurement<T>
impl<T> DelayedMeasurement<T>
pub fn new(f: Box<dyn Fn() -> Result<T> + Send>) -> DelayedMeasurement<T>
sourcepub fn done(&self) -> Result<T>
pub fn done(&self) -> Result<T>
Examples found in repository?
examples/info.rs (line 102)
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
fn main() {
let sys = System::new();
match sys.mounts() {
Ok(mounts) => {
println!("\nMounts:");
for mount in mounts.iter() {
println!("{} ---{}---> {} (available {} of {})",
mount.fs_mounted_from, mount.fs_type, mount.fs_mounted_on, mount.avail, mount.total);
}
}
Err(x) => println!("\nMounts: error: {}", x)
}
match sys.mount_at("/") {
Ok(mount) => {
println!("\nMount at /:");
println!("{} ---{}---> {} (available {} of {})",
mount.fs_mounted_from, mount.fs_type, mount.fs_mounted_on, mount.avail, mount.total);
}
Err(x) => println!("\nMount at /: error: {}", x)
}
match sys.block_device_statistics() {
Ok(stats) => {
for blkstats in stats.values() {
println!("{}: {:?}", blkstats.name, blkstats);
}
}
Err(x) => println!("\nBlock statistics error: {}", x)
}
match sys.networks() {
Ok(netifs) => {
println!("\nNetworks:");
for netif in netifs.values() {
println!("{} ({:?})", netif.name, netif.addrs);
}
}
Err(x) => println!("\nNetworks: error: {}", x)
}
match sys.networks() {
Ok(netifs) => {
println!("\nNetwork interface statistics:");
for netif in netifs.values() {
println!("{} statistics: ({:?})", netif.name, sys.network_stats(&netif.name));
}
}
Err(x) => println!("\nNetworks: error: {}", x)
}
match sys.battery_life() {
Ok(battery) =>
print!("\nBattery: {}%, {}h{}m remaining",
battery.remaining_capacity*100.0,
battery.remaining_time.as_secs() / 3600,
battery.remaining_time.as_secs() % 60),
Err(x) => print!("\nBattery: error: {}", x)
}
match sys.on_ac_power() {
Ok(power) => println!(", AC power: {}", power),
Err(x) => println!(", AC power: error: {}", x)
}
match sys.memory() {
Ok(mem) => println!("\nMemory: {} used / {} ({} bytes) total ({:?})", saturating_sub_bytes(mem.total, mem.free), mem.total, mem.total.as_u64(), mem.platform_memory),
Err(x) => println!("\nMemory: error: {}", x)
}
match sys.swap() {
Ok(swap) => println!("\nSwap: {} used / {} ({} bytes) total ({:?})", saturating_sub_bytes(swap.total, swap.free), swap.total, swap.total.as_u64(), swap.platform_swap),
Err(x) => println!("\nSwap: error: {}", x)
}
match sys.load_average() {
Ok(loadavg) => println!("\nLoad average: {} {} {}", loadavg.one, loadavg.five, loadavg.fifteen),
Err(x) => println!("\nLoad average: error: {}", x)
}
match sys.uptime() {
Ok(uptime) => println!("\nUptime: {:?}", uptime),
Err(x) => println!("\nUptime: error: {}", x)
}
match sys.boot_time() {
Ok(boot_time) => println!("\nBoot time: {}", boot_time),
Err(x) => println!("\nBoot time: error: {}", x)
}
match sys.cpu_load_aggregate() {
Ok(cpu)=> {
println!("\nMeasuring CPU load...");
thread::sleep(Duration::from_secs(1));
let cpu = cpu.done().unwrap();
println!("CPU load: {}% user, {}% nice, {}% system, {}% intr, {}% idle ",
cpu.user * 100.0, cpu.nice * 100.0, cpu.system * 100.0, cpu.interrupt * 100.0, cpu.idle * 100.0);
},
Err(x) => println!("\nCPU load: error: {}", x)
}
match sys.cpu_temp() {
Ok(cpu_temp) => println!("\nCPU temp: {}", cpu_temp),
Err(x) => println!("\nCPU temp: {}", x)
}
match sys.socket_stats() {
Ok(stats) => println!("\nSystem socket statistics: {:?}", stats),
Err(x) => println!("\nSystem socket statistics: error: {}", x)
}
}