#linux-kernel #uptime #version #memory #statistics #networking #information

bin+lib sysinfo_linux

A Rust library for retrieving Linux system information, including kernel version, uptime, available memory, and network interface statistics

4 releases

0.1.5 Nov 21, 2024
0.1.4 Nov 6, 2024
0.1.3 Nov 6, 2024
0.1.2 Nov 5, 2024

#275 in Unix APIs

Download history 334/week @ 2024-11-04 6/week @ 2024-11-11 154/week @ 2024-11-18 5/week @ 2024-11-25 9/week @ 2024-12-02 33/week @ 2024-12-09

201 downloads per month

MIT/Apache

6KB

sysinfo_linux

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.

Installation

Add this to your Cargo.toml:

[dependencies]
sysinfo_linux = "0.1.2"
thiserror = "1.0" 

Usage

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),
    }
}

Features

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.

Contributing

Feel free to submit issues or pull requests. Contributions are always welcome!

License

This project is licensed under the MIT License

Author

bensatlantik

Dependencies

~255–710KB
~17K SLoC