From cdc42088b96dfd3045def876f03f11ded80a8974 Mon Sep 17 00:00:00 2001 From: fbt Date: Sat, 1 Dec 2018 23:14:10 +0300 Subject: [PATCH] Use available memory Signed-off-by: fbt --- mod/memory | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mod/memory b/mod/memory index 369239f..812ddc3 100644 --- a/mod/memory +++ b/mod/memory @@ -4,22 +4,21 @@ class ModMemory < Worker def mainloop() while true do mem = {} - data = File.read("/proc/meminfo").scan(/Mem(Total|Available):\s+([0-9]+)/).map do |k, v| - mem[k] = v + data = File.read("/proc/meminfo").scan(/(.+):\s+([0-9]+)/).map do |k, v| + mem[k] = v.to_i end - mem["free_part"] = mem["Available"].to_i/(mem["Total"].to_i/100) - mem["used_part"] = 100 - mem["free_part"] + mem["avail_part"] = mem["MemAvailable"]/(mem["MemTotal"]/100) - if mem["used_part"] > @my_config['crit_value'] + if mem["avail_part"] < @my_config['crit_value'] fg_colour = @my_config['crit_colour'] - elsif mem["used_part"] > @my_config['warn_value'] + elsif mem["avail_part"] < @my_config['warn_value'] fg_colour = @my_config['warn_colour'] else fg_colour = @my_config['ok_colour'] end - self.write "%%{F%s}%s%%{F-}" % [ fg_colour, mem["used_part"].to_s ] + self.write "%%{F%s}%s%%{F-}" % [ fg_colour, mem["avail_part"].to_s ] sleep(1) end