diff options
author | Tim Keller <tjk@tjkeller.xyz> | 2024-10-18 21:49:17 -0500 |
---|---|---|
committer | Tim Keller <tjk@tjkeller.xyz> | 2024-10-18 21:49:17 -0500 |
commit | 923eb46350b1102749eb05cd2120c96cc6a715d0 (patch) | |
tree | 811da20b4195d4b5c65c8ac0090982a4a23f6a7d /widgets/ram.lua | |
download | awesome-923eb46350b1102749eb05cd2120c96cc6a715d0.tar.xz awesome-923eb46350b1102749eb05cd2120c96cc6a715d0.zip |
initial commit
Diffstat (limited to 'widgets/ram.lua')
-rw-r--r-- | widgets/ram.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/widgets/ram.lua b/widgets/ram.lua new file mode 100644 index 0000000..44ab314 --- /dev/null +++ b/widgets/ram.lua @@ -0,0 +1,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") |