Crates.io | sysinfo_linux |
lib.rs | sysinfo_linux |
version | 0.1.5 |
source | src |
created_at | 2024-11-05 14:23:01.204679 |
updated_at | 2024-11-21 01:51:06.91579 |
description | A Rust library for retrieving Linux system information, including kernel version, uptime, available memory, and network interface statistics. |
homepage | |
repository | |
max_upload_size | |
id | 1436596 |
size | 7,448 |
A Rust library to fetch and display various system information on Linux systems. This library provides methods to retrieve kernel version, system uptime, available memory, and network interface statistics.
Add this to your Cargo.toml
:
[dependencies]
sysinfo_linux = "0.1.2"
thiserror = "1.0"
Here's a basic example of how to use the library:
use sysinfo_linux::SystemInfo;
fn main() {
// Get the Linux kernel version
match SystemInfo::kernel_version() {
Some(version) => println!("Kernel Version: {}", version),
None => eprintln!("Failed to get kernel version"),
}
// Get the system uptime
match SystemInfo::system_uptime() {
Ok(uptime) => println!("System Uptime: {:.2} seconds", uptime),
Err(e) => eprintln!("Error getting uptime: {}", e),
}
// Get the available memory
match SystemInfo::available_memory() {
Ok(memory) => println!("Available Memory: {} kB", memory),
Err(e) => eprintln!("Error getting available memory: {}", e),
}
// Get network interface statistics
match SystemInfo::network_interface_stats() {
Ok(interfaces) => {
for interface in interfaces {
println!("Interface: {}\n RX Bytes: {}\n TX Bytes: {}\n",
interface.name, interface.rx_bytes, interface.tx_bytes);
}
}
Err(e) => eprintln!("Error getting network interface statistics: {}", e),
}
}
Kernel Version: Retrieve the Linux kernel version using uname.
System Uptime: Fetch the system uptime from /proc/uptime.
Available Memory: Get the available memory in kilobytes from /proc/meminfo.
Network Interface Statistics: Fetch statistics for each network interface from /proc/net/dev.
Feel free to submit issues or pull requests. Contributions are always welcome!
This project is licensed under the MIT License
bensatlantik