From f86c60d2fdd846cdd943d4baef967bd0a2aaf0a5 Mon Sep 17 00:00:00 2001 From: mutlusun Date: Wed, 25 Jan 2017 17:55:37 +0100 Subject: [PATCH] port uptime widget to freebsd --- widgets/uptime_freebsd.lua | 30 ++++++++++++++++++++++++ widgets/{uptime.lua => uptime_linux.lua} | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 widgets/uptime_freebsd.lua rename widgets/{uptime.lua => uptime_linux.lua} (90%) diff --git a/widgets/uptime_freebsd.lua b/widgets/uptime_freebsd.lua new file mode 100644 index 0000000..9e075e5 --- /dev/null +++ b/widgets/uptime_freebsd.lua @@ -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 }) diff --git a/widgets/uptime.lua b/widgets/uptime_linux.lua similarity index 90% rename from widgets/uptime.lua rename to widgets/uptime_linux.lua index 0e996ac..a6976b8 100644 --- a/widgets/uptime.lua +++ b/widgets/uptime_linux.lua @@ -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 })