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.
This commit is contained in:
Adrian C. (anrxc) 2009-11-11 03:55:03 +01:00
parent 7be560b70c
commit 493150c888
4 changed files with 18 additions and 51 deletions

15
README
View File

@ -152,16 +152,11 @@ vicious.widgets.thermal
- takes the thermal zone as an argument, i.e. "thermal_zone0"
- returns 1st value as temperature of requested thermal zone
vicious.widgets.load
- provides system load averages for the past 1, 5, and 15 minutes
- returns 1st value as load average for past 1 minute, 2nd for 5
minutes and 3rd for 15 minutes
vicious.widgets.uptime
- provides system uptime information
- returns 1st value as total uptime, 2nd as uptime in days, 3rd as
uptime in hours, 4th as uptime in minutes and 5th as uptime in
seconds
- provides system uptime and load information
- returns 1st value as uptime in days, 2nd as uptime in hours, 3rd
as uptime in minutes, 4th as load average for past 1 minute, 5th
for 5 minutes and 6th for 15 minutes
vicious.widgets.bat
- provides state, charge, and remaining time for a requested battery
@ -375,7 +370,7 @@ Example
uptimewidget = widget({ type = 'textbox' })
vicious.register(uptimewidget, vicious.widgets.uptime,
function (widget, args)
return string.format('Uptime: %2dd %02d:%02d ', args[2], args[3], args[4])
return string.format('Uptime: %2dd %02d:%02d ', args[1], args[2], args[3])
end, 61)
- uses string.format for padding uptime values to a minimum amount

View File

@ -25,7 +25,6 @@ require("vicious.cpu")
require("vicious.cpuinf")
require("vicious.cpufreq")
require("vicious.thermal")
require("vicious.load")
require("vicious.uptime")
require("vicious.bat")
require("vicious.mem")

View File

@ -1,31 +0,0 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2009, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable
local string = { match = string.match }
-- }}}
-- Load: provides system load averages for the past 1, 5, and 15 minutes
module("vicious.load")
-- {{{ Load widget type
local function worker(format)
local f = io.open('/proc/loadavg')
local line = f:read("*line")
f:close()
local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
string.match(line, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)")
return {tonumber(l1), tonumber(l5), tonumber(l15)}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })

View File

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