2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2013, Luke Bonham
|
|
|
|
* (c) 2010-2012, Peter Hofmann
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2015-10-20 15:17:44 +02:00
|
|
|
local newtimer = require("lain.helpers").newtimer
|
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
local wibox = require("wibox")
|
|
|
|
|
2013-09-20 03:01:04 +02:00
|
|
|
local io = { open = io.open }
|
2015-05-19 15:41:33 +02:00
|
|
|
local string = { match = string.match }
|
2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
|
|
-- System load
|
|
|
|
-- lain.widgets.sysload
|
|
|
|
local sysload = {}
|
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
local function worker(args)
|
2013-09-07 12:06:42 +02:00
|
|
|
local args = args or {}
|
2015-10-20 15:17:44 +02:00
|
|
|
local timeout = args.timeout or 2
|
2013-09-10 23:02:11 +02:00
|
|
|
local settings = args.settings or function() end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
sysload.widget = wibox.widget.textbox('')
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
function update()
|
2013-09-07 12:06:42 +02:00
|
|
|
local f = io.open("/proc/loadavg")
|
2015-07-26 00:59:23 +02:00
|
|
|
local ret = f:read("*all")
|
2013-09-07 12:06:42 +02:00
|
|
|
f:close()
|
2013-09-13 18:15:25 +02:00
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2015-10-20 15:17:44 +02:00
|
|
|
widget = sysload.widget
|
|
|
|
settings()
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2015-10-20 15:17:44 +02:00
|
|
|
newtimer("sysload", timeout, update)
|
2013-09-11 19:39:14 +02:00
|
|
|
return sysload.widget
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(sysload, { __call = function(_, ...) return worker(...) end })
|