port uptime widget to freebsd
This commit is contained in:
parent
22d49a9e5d
commit
f86c60d2fd
|
@ -0,0 +1,30 @@
|
||||||
|
-- {{{ Grab environment
|
||||||
|
local tonumber = tonumber
|
||||||
|
local setmetatable = setmetatable
|
||||||
|
local math = { floor = math.floor }
|
||||||
|
local string = { match = string.match }
|
||||||
|
local helpers = require("vicious.helpers")
|
||||||
|
local os = { time = os.time }
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
-- Uptime: provides system uptime and load information
|
||||||
|
-- vicious.widgets.uptime
|
||||||
|
local uptime_freebsd = {}
|
||||||
|
|
||||||
|
|
||||||
|
-- {{{ Uptime widget type
|
||||||
|
local function worker(format)
|
||||||
|
local l1, l5, l15 = string.match(helpers.sysctl("vm.loadavg"), "{ ([%d]+%.[%d]+) ([%d]+%.[%d]+) ([%d]+%.[%d]+) }")
|
||||||
|
local up_t = os.time() - tonumber(string.match(helpers.sysctl("kern.boottime"), "sec = ([%d]+)"))
|
||||||
|
|
||||||
|
-- Get system uptime
|
||||||
|
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)
|
||||||
|
|
||||||
|
return {up_d, up_h, up_m, l1, l5, l15}
|
||||||
|
end
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
return setmetatable(uptime_freebsd, { __call = function(_, ...) return worker(...) end })
|
|
@ -14,7 +14,7 @@ local helpers = require("vicious.helpers")
|
||||||
|
|
||||||
-- Uptime: provides system uptime and load information
|
-- Uptime: provides system uptime and load information
|
||||||
-- vicious.widgets.uptime
|
-- vicious.widgets.uptime
|
||||||
local uptime = {}
|
local uptime_linux = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Uptime widget type
|
-- {{{ Uptime widget type
|
||||||
|
@ -33,4 +33,4 @@ local function worker(format)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(uptime, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(uptime_linux, { __call = function(_, ...) return worker(...) end })
|
Loading…
Reference in New Issue