diff options
author | mustafa salih <mustafasalih1991@gmail.com> | 2021-01-18 09:42:18 +0300 |
---|---|---|
committer | mustafa salih <mustafasalih1991@gmail.com> | 2021-01-18 09:42:18 +0300 |
commit | 3596f13cc353aac4a675086af05643d2bad91ac1 (patch) | |
tree | cbaf078617eda25bfb90f78f92a6f9a7306ee3de /src/utils | |
parent | 4f83d10cf86bcc4c2364e7f5f24be34712242b04 (diff) |
added reading load average
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/load_average.rs | 16 | ||||
-rw-r--r-- | src/utils/mod.rs | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/load_average.rs b/src/utils/load_average.rs new file mode 100644 index 0000000..2cd271f --- /dev/null +++ b/src/utils/load_average.rs @@ -0,0 +1,16 @@ +use crate::types::Config; +use std::fs::File; +use std::io::Read; + +pub fn get_load_avg(config: &Config) -> String { + let mut buf = String::new(); + match File::open("/proc/loadavg") { + Ok(mut file) => match file.read_to_string(&mut buf) { + Ok(data) => data, + _ => return String::from(""), + }, + _ => return String::from("Error"), + }; + let buf = buf.split_whitespace().collect::<Vec<_>>()[0]; + format!(" {} {} {}", config.loadavg.icon, buf, config.seperator) +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index b497999..6834d49 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,6 +1,7 @@ pub mod battery; pub mod cpu; pub mod disk; +pub mod load_average; pub mod memory; pub mod mpd; pub mod spotify; |