2022-12-24 20:58:57 +00:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2013, Luca CPZ
|
|
|
|
* (c) 2010-2012, Peter Hofmann
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
local helpers = require('lain.helpers')
|
|
|
|
local wibox = require('wibox')
|
2022-12-24 20:58:57 +00:00
|
|
|
local open, match = io.open, string.match
|
|
|
|
|
|
|
|
-- System load
|
|
|
|
-- lain.widget.sysload
|
|
|
|
|
|
|
|
local function factory(args)
|
2023-01-25 19:10:58 +00:00
|
|
|
args = args or {}
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
local sysload = { widget = args.widget or wibox.widget.textbox() }
|
|
|
|
local timeout = args.timeout or 2
|
|
|
|
local settings = args.settings or function() end
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
function sysload.update()
|
|
|
|
local f = open('/proc/loadavg')
|
|
|
|
local ret = f:read('*all')
|
|
|
|
f:close()
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
load_1, load_5, load_15 = match(ret, '([^%s]+) ([^%s]+) ([^%s]+)')
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
widget = sysload.widget
|
|
|
|
settings()
|
|
|
|
end
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
helpers.newtimer('sysload', timeout, sysload.update)
|
2022-12-24 20:58:57 +00:00
|
|
|
|
2023-01-25 19:10:58 +00:00
|
|
|
return sysload
|
2022-12-24 20:58:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return factory
|