blob: 44ab3148b561a6ca3063604a36c89b2286d65e15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local wibox = require("wibox")
local widgets = require("util.widgets")
function linux_ram_usage(widget)
-- read meminfo
local meminfof = io.open("/proc/meminfo")
local total = meminfof:read():match("%d+")
local free = meminfof:read():match("%d+")
meminfof:read() -- memavailable not used
local buffers = meminfof:read():match("%d+")
local cached = meminfof:read():match("%d+")
meminfof:close()
-- calc
if total == nil then
return
end
local used = (total - free - buffers - cached) * 100 / total
widget:set_text(math.floor(used))
end
-- return correct widget for os
if osname == "Linux" then
return widgets.watchfn(linux_ram_usage, 5)
end
return wibox.widget.textbox("unsupported os")
|