Use available mem instead of free mem
This commit is contained in:
parent
8bad155f15
commit
e6719dc6f5
@ -29,7 +29,7 @@ impl bar_modules::BarModuleActions for UnibarModuleMemory {
|
|||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
let path = Path::new("/proc/meminfo");
|
let path = Path::new("/proc/meminfo");
|
||||||
|
|
||||||
// Contents of '/process/meminfo' has memory information
|
// Contents of '/proc/meminfo' has memory information
|
||||||
let mut meminfo_file = match File::open(&path) {
|
let mut meminfo_file = match File::open(&path) {
|
||||||
Err(why) => panic!("couldn't open {}: {}", path.display(), why),
|
Err(why) => panic!("couldn't open {}: {}", path.display(), why),
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
@ -48,12 +48,12 @@ impl bar_modules::BarModuleActions for UnibarModuleMemory {
|
|||||||
// --------------------
|
// --------------------
|
||||||
// MemTotal: 7822812 kB\nMemFree: 399244 kB\nMemAvailable: 3986504 kB
|
// MemTotal: 7822812 kB\nMemFree: 399244 kB\nMemAvailable: 3986504 kB
|
||||||
fn get_content(&self) -> String {
|
fn get_content(&self) -> String {
|
||||||
let re = Regex::new(r"MemTotal:\s+(\d+)\s+kB\nMemFree:\s+(\d+)").unwrap();
|
let re = Regex::new(r"MemTotal:\s+(\d+)\s+kB\nMemFree:\s+(\d+)\s+kB\nMemAvailable:\s+(\d+)").unwrap();
|
||||||
let caps = re.captures(self.meminfo_str.as_str()).unwrap();
|
let caps = re.captures(self.meminfo_str.as_str()).unwrap();
|
||||||
|
|
||||||
let total_mem :f32 = caps.get(1).unwrap().as_str().parse::<f32>().unwrap();
|
let total_mem :f32 = caps.get(1).unwrap().as_str().parse::<f32>().unwrap();
|
||||||
let free_mem :f32 = caps.get(2).unwrap().as_str().parse::<f32>().unwrap();
|
let avail_mem :f32 = caps.get(3).unwrap().as_str().parse::<f32>().unwrap();
|
||||||
return format!("{}%", ((total_mem - free_mem)/total_mem * 100.0).ceil() as i32);
|
return format!("{}%", ((total_mem - avail_mem)/total_mem * 100.0).ceil() as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user