linux-sysinfo

Crates.iolinux-sysinfo
lib.rslinux-sysinfo
version0.1.0
created_at2025-07-28 11:27:14.289315+00
updated_at2025-07-28 11:27:14.289315+00
descriptionA lightweight Rust crate to get per-core CPU usage info on Linux via /proc/stat
homepage
repositoryhttps://github.com/canmi/linux-sysinfo
max_upload_size
id1771028
size8,794
Canmi (canmi21)

documentation

https://docs.rs/linux-sysinfo

README

linux-sysinfo

A lightweight Rust crate to get per-core CPU usage information on Linux systems by reading /proc/stat.

Features

  • Reads CPU stats directly from /proc/stat
  • Calculates per-core CPU usage over a 1-second interval
  • Returns CPU usage data as JSON string for easy integration
  • No external dependencies besides serde and serde_json

Installation

Add this to your Cargo.toml:

[dependencies]
linux-sysinfo = "0.1.0"

Usage

use linux_sysinfo::get_cpu_usage_json;

fn main() {
    match get_cpu_usage_json() {
        Ok(json) => println!("{}", json),
        Err(e) => eprintln!("Error: {}", e),
    }
}

Example output

[
  {
    "core": 0,
    "usage": 7.32
  },
  {
    "core": 1,
    "usage": 4.56
  },
  {
    "core": 2,
    "usage": 9.14
  },
  {
    "core": 3,
    "usage": 12.43
  }
]

Commit count: 0

cargo fmt