lain/widgets/sysload.lua

47 lines
1.1 KiB
Lua
Raw Normal View History

2013-09-07 12:06:42 +02:00
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]
2013-09-10 23:02:11 +02:00
local newtimer = require("lain.helpers").newtimer
2013-09-07 12:06:42 +02:00
local wibox = require("wibox")
local io = io
local string = { format = string.format,
match = string.match }
local setmetatable = setmetatable
-- System load
-- lain.widgets.sysload
local sysload = {}
function worker(args)
local args = args or {}
2013-09-10 23:02:11 +02:00
local timeout = args.timeout or 5
local settings = args.settings or function() end
2013-09-07 12:06:42 +02:00
2013-09-10 23:02:11 +02:00
widget = wibox.widget.textbox('')
2013-09-07 12:06:42 +02:00
2013-09-10 23:02:11 +02:00
function update()
2013-09-07 12:06:42 +02:00
local f = io.open("/proc/loadavg")
local ret = f:read("*all")
f:close()
2013-09-10 23:02:11 +02:00
a, b, c = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
2013-09-07 12:06:42 +02:00
2013-09-10 23:02:11 +02:00
settings()
2013-09-07 12:06:42 +02:00
end
2013-09-10 23:02:11 +02:00
newtimer("sysload", timeout, update)
2013-09-07 12:06:42 +02:00
2013-09-10 23:02:11 +02:00
return widget
2013-09-07 12:06:42 +02:00
end
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })