lua rewrite
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
local util = require("modules/util")
|
||||
|
||||
-- RAM amount in GB
|
||||
local function get_ram_gb()
|
||||
local free, total, avail
|
||||
|
||||
util.for_line_in_file("/proc/meminfo", function(line)
|
||||
local total_match = line:match("^MemTotal%s*:%s*(.+)%s*[kK][bB]")
|
||||
local avail_match = line:match("^MemAvailable%s*:%s*(.+)%s*[kK][bB]")
|
||||
|
||||
if total_match then
|
||||
total = tonumber(total_match)
|
||||
end
|
||||
|
||||
if avail_match then
|
||||
avail = tonumber(avail_match)
|
||||
end
|
||||
|
||||
if total and avail then
|
||||
free = string.format("%.1f GB", (total - avail) / 1000000)
|
||||
end
|
||||
|
||||
return free ~= nil
|
||||
end)
|
||||
|
||||
return free
|
||||
end
|
||||
|
||||
return { name = "ram", cmd = get_ram_gb }
|
||||
Reference in New Issue
Block a user