lain/widget/sysload.lua

45 lines
1014 B
Lua
Raw Normal View History

2013-09-07 12:06:42 +02:00
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2010-2012, Peter Hofmann
2013-09-07 12:06:42 +02:00
--]]
local requirePrefix = tostring(...):match(".*lain") or ""
if requirePrefix then
requirePrefix = requirePrefix .. "."
end
local helpers = require(requirePrefix .. "helpers")
local wibox = require("wibox")
local open, match = io.open, string.match
2013-09-07 12:06:42 +02:00
-- System load
2017-02-08 14:15:48 +01:00
-- lain.widget.sysload
2013-09-07 12:06:42 +02:00
2017-02-08 20:45:11 +01:00
local function factory(args)
2020-11-29 22:48:32 +01:00
args = args or {}
local sysload = { widget = args.widget or wibox.widget.textbox() }
2017-01-25 17:13:14 +01: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
2017-01-27 14:35:27 +01:00
function sysload.update()
local f = 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
load_1, load_5, load_15 = 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
2017-01-27 14:35:27 +01:00
helpers.newtimer("sysload", timeout, sysload.update)
2017-01-24 18:19:15 +01:00
2017-01-25 17:13:14 +01:00
return sysload
2013-09-07 12:06:42 +02:00
end
return factory