getting load-average programmatically, fully support BSD soon
This commit is contained in:
parent
96b47f1999
commit
674f6811fe
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -527,7 +527,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsblocks"
|
name = "rsblocks"
|
||||||
version = "0.1.16"
|
version = "0.1.17"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alsa",
|
"alsa",
|
||||||
"battery",
|
"battery",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rsblocks"
|
name = "rsblocks"
|
||||||
version = "0.1.16"
|
version = "0.1.17"
|
||||||
authors = ["mustafa salih <mustafasalih1991@gmail.com>"]
|
authors = ["mustafa salih <mustafasalih1991@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
use crate::types::ThreadsData;
|
use crate::types::ThreadsData;
|
||||||
use std::fs::File;
|
use nix::sys::sysinfo;
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
pub fn get_load_avg() -> ThreadsData {
|
pub fn get_load_avg() -> ThreadsData {
|
||||||
let mut buf = String::new();
|
let load = sysinfo::sysinfo().unwrap().load_average().0;
|
||||||
match File::open("/proc/loadavg") {
|
let data = format!(
|
||||||
Ok(mut file) => match file.read_to_string(&mut buf) {
|
" {} {:.2} {}",
|
||||||
Ok(data) => data,
|
CONFIG.loadavg.icon, load, CONFIG.seperator
|
||||||
_ => return ThreadsData::LoadAvg(String::from("")),
|
);
|
||||||
},
|
|
||||||
_ => return ThreadsData::LoadAvg(String::from("Error")),
|
|
||||||
};
|
|
||||||
let buf = buf.split_whitespace().collect::<Vec<_>>()[0];
|
|
||||||
let data = format!(" {} {} {}", CONFIG.loadavg.icon, buf, CONFIG.seperator);
|
|
||||||
ThreadsData::LoadAvg(data)
|
ThreadsData::LoadAvg(data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user