From 493150c88899572fad92aa04457c90027740aca5 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 11 Nov 2009 03:55:03 +0100 Subject: uptime: merged with load widget type Total uptime and seconds are no longer returned. Returns are now: days, hours, minutes, load avg 1, load avg 5 and load avg 15. --- uptime.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'uptime.lua') diff --git a/uptime.lua b/uptime.lua index 1784985..c7082c1 100644 --- a/uptime.lua +++ b/uptime.lua @@ -5,31 +5,35 @@ --------------------------------------------------- -- {{{ Grab environment -local io = { open = io.open } local setmetatable = setmetatable local math = { floor = math.floor } local string = { match = string.match } +local helpers = require("vicious.helpers") -- }}} --- Uptime: provides system uptime information +-- Uptime: provides system uptime and load information module("vicious.uptime") -- {{{ Uptime widget type local function worker(format) - -- Get /proc/uptime - local f = io.open("/proc/uptime") - local line = f:read("*line") - f:close() + local proc = setmetatable( + { _path = "/proc" }, + helpers.pathtotable + ) - local up_t = math.floor(string.match(line, "[%d]+")) + -- Get system uptime + local up_t = math.floor(string.match(proc.uptime, "[%d]+")) 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) - local up_s = math.floor(((up_t % (3600 * 24)) % 3600) % 60) - return {up_t, up_d, up_h, up_m, up_s} + -- 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 -- }}} -- cgit v1.2.3