Packages
Elixir library providing Bluetooth Low Energy (BLE) client functionality through a Rustler NIF. Uses the btleplug crate to scan for, connect to, and interact with BLE peripherals. POC basic functionality and only client (central) mode is supported resp. usable currently.
Current section
Files
Jump to
Current section
Files
native/btleplug_client/src/gatt_sysinfo_characteristic.rs
use sysinfo::System;
let mut sys = System::new();
use sysinfo::{
Components, Disks, Networks, System,
};
// Please note that we use "new_all" to ensure that all lists of
// CPUs and processes are filled!
let mut sys = System::new_all();
// First we update all information of our `System` struct.
sys.refresh_all();
println!("=> system:");
// RAM and swap information:
println!("total memory: {} bytes", sys.total_memory());
println!("used memory : {} bytes", sys.used_memory());
println!("total swap : {} bytes", sys.total_swap());
println!("used swap : {} bytes", sys.used_swap());
// Display system information:
println!("System name: {:?}", System::name());
println!("System kernel version: {:?}", System::kernel_version());
println!("System OS version: {:?}", System::os_version());
println!("System host name: {:?}", System::host_name());
// Number of CPUs:
println!("NB CPUs: {}", sys.cpus().len());
// Display processes ID, name na disk usage:
for (pid, process) in sys.processes() {
println!("[{pid}] {:?} {:?}", process.name(), process.disk_usage());
}
// We display all disks' information:
println!("=> disks:");
let disks = Disks::new_with_refreshed_list();
for disk in &disks {
println!("{disk:?}");
}
// Network interfaces name, total data received and total data transmitted:
let networks = Networks::new_with_refreshed_list();
println!("=> networks:");
for (interface_name, data) in &networks {
println!(
"{interface_name}: {} B (down) / {} B (up)",
data.total_received(),
data.total_transmitted(),
);
// If you want the amount of data received/transmitted since last call
// to `Networks::refresh`, use `received`/`transmitted`.
}
// Components temperature:
let components = Components::new_with_refreshed_list();
println!("=> components:");
for component in &components {
println!("{component:?}");
}
loop {
sys.refresh_cpu_usage(); // Refreshing CPU usage.
for cpu in sys.cpus() {
print!("{}% ", cpu.cpu_usage());
}
// Sleeping to let time for the system to run for long
// enough to have useful information.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
}