port uptime widget to freebsd

This commit is contained in:
mutlusun 2017-01-25 17:55:37 +01:00 committed by Jörg Thalheim
parent 22d49a9e5d
commit f86c60d2fd
No known key found for this signature in database
GPG Key ID: CA4106B8D7CC79FA
2 changed files with 32 additions and 2 deletions

View File

@ -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 })

View File

@ -14,7 +14,7 @@ local helpers = require("vicious.helpers")
-- Uptime: provides system uptime and load information
-- vicious.widgets.uptime
local uptime = {}
local uptime_linux = {}
-- {{{ Uptime widget type
@ -33,4 +33,4 @@ local function worker(format)
end
-- }}}
return setmetatable(uptime, { __call = function(_, ...) return worker(...) end })
return setmetatable(uptime_linux, { __call = function(_, ...) return worker(...) end })