2 -- Copyright (c) 2008, Dave O'Neill <dmo@dmo.ca>
4 -- Simple load applet for wmii bar.
6 local wmii
= require("wmii")
7 local io
= require("io")
8 local math
= require("math")
9 local string = require("string")
10 local tonumber = tonumber
16 local palette
= { "#888888",
30 local widget
= wmii
.widget
:new ("800_loadavg")
32 local function loadavg_timer (time_since_update
)
34 local file
= io
.open("/proc/loadavg", "r")
38 local txt
= file
:read("*all")
40 if type(txt
) == 'string' then
41 local one
,five
,ten
= txt
:match("^([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)%s+")
42 if type(one
) == 'string' then
43 bartext
= string.format("%.1f %.1f %.1f", one
, five
, ten
)
47 local current_avg
= tonumber(one
)
48 if type(current_avg
) == "number" then
49 local index
= math
.min(math
.floor(current_avg
* (#palette
-1)) + 1, #palette
)
50 local normal
= wmii
.get_ctl("normcolors")
51 colors
= string.gsub(normal
, "^%S+", palette
[index
], 1)
56 widget
:show(bartext
, colors
)
58 -- positive number of seconds before next wakeup
59 -- nil, or no return, to repeat the last schedule
60 -- -1 to stop the timer
64 local timer
= wmii
.timer
:new( loadavg_timer
, 1)