blob: 2347ca40a2111e8b3398041bbf82eb2229b3afbc (
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
35
36
|
local wibox = require("wibox")
local widgets = require("util.widgets")
local osname = require("util.osname")
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")
|