vicious/uptime.lua

38 lines
1.2 KiB
Lua
Raw Normal View History

2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- Licensed under the GNU General Public License v2
2009-11-04 23:39:38 +01:00
-- * (c) 2009, Adrian C. <anrxc@sysphere.org>
-- * (c) 2008, Lucas de Vries <lucas@glacicle.com>
2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- {{{ Grab environment
local setmetatable = setmetatable
local math = { floor = math.floor }
2009-10-05 00:10:47 +02:00
local string = { match = string.match }
local helpers = require("vicious.helpers")
-- }}}
-- Uptime: provides system uptime and load information
module("vicious.uptime")
-- {{{ Uptime widget type
2009-08-07 17:41:10 +02:00
local function worker(format)
local proc = helpers.pathtotable("/proc")
-- Get system uptime
local up_t = math.floor(string.match(proc.uptime, "[%d]+"))
2009-10-05 00:10:47 +02:00
local up_d = math.floor(up_t / (3600 * 24))
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
-- Get load averages
local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
string.match(proc.loadavg, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)")
return {up_d, up_h, up_m, l1, l5, l15}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })