sysinfo_linux

Crates.iosysinfo_linux
lib.rssysinfo_linux
version0.1.5
sourcesrc
created_at2024-11-05 14:23:01.204679
updated_at2024-11-21 01:51:06.91579
descriptionA Rust library for retrieving Linux system information, including kernel version, uptime, available memory, and network interface statistics.
homepage
repository
max_upload_size
id1436596
size7,448
Ben Santora (bensatlantik)

documentation

README

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

Commit count: 0

cargo fmt