Crates.io | oxide_linux2 |
lib.rs | oxide_linux2 |
version | 0.1.6 |
source | src |
created_at | 2024-11-02 09:27:02.914973 |
updated_at | 2024-11-06 07:14:26.943574 |
description | A Rust library for retrieving system information on Linux, including kernel version, system uptime, available memory, CPU information, load averages, and disk usage. |
homepage | |
repository | https://github.com/bensatlantik/oxide_linux2 |
max_upload_size | |
id | 1432693 |
size | 12,783 |
oxide_linux2
is a Rust library that provides utilities for retrieving system information on Linux. It allows users to easily fetch details like kernel version, system uptime, available memory, CPU information, load averages, and disk usage.
To use oxide_linux2
in your project, add it as a dependency in your Cargo.toml
file:
[dependencies]
oxide_linux2 = "0.1.5"
thiserror = "1.0"
nix = "0.23.0"
Here's an example of how to use the library:
use oxide_linux2::SystemInfo;
fn main() {
// Kernel version
if let Some(kernel_version) = SystemInfo::kernel_version() {
println!("Kernel Version: {}", kernel_version);
} else {
println!("Failed to get Kernel Version.");
}
// System uptime
match SystemInfo::system_uptime() {
Ok(uptime) => println!("System Uptime: {:.2} seconds", uptime),
Err(e) => println!("Failed to get System Uptime: {}", e),
}
// Available memory
match SystemInfo::available_memory() {
Ok(memory) => println!("Available Memory: {} kB", memory),
Err(e) => println!("Failed to get Available Memory: {}", e),
}
// CPU information
match SystemInfo::cpu_info() {
Ok(cpu_info) => println!("CPU Information: \n{}", cpu_info),
Err(e) => println!("Failed to get CPU Information: {}", e),
}
// Load average
match SystemInfo::load_average() {
Ok(loadavg) => println!("Load Average: {:.2}, {:.2}, {:.2}", loadavg[0], loadavg[1], loadavg[2]),
Err(e) => println!("Failed to get Load Average: {}", e),
}
// Disk usage
match SystemInfo::disk_usage("/") {
Ok((total, free)) => println!("Disk Usage: Total - {} bytes, Free - {} bytes", total, free),
Err(e) => println!("Failed to get Disk Usage: {}", e),
}
}
This project is licensed under the MIT License
Ben Santora bensatlantik@gmail.com