WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

rfshub/linux-sysinfo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  }
]

About

A lightweight Rust crate to get cpu info.

Topics

Resources

License

Stars

Watchers

Forks

Languages