]> git.decadent.org.uk Git - ion3.git/blob - utils/ion-statusd/statusd_load.lua
Update cfg_kludge_flash for Flash 10
[ion3.git] / utils / ion-statusd / statusd_load.lua
1 --
2 -- ion/mod_statusbar/ion-statusd/statusd_load.lua
3 -- 
4 -- Copyright (c) Tuomo Valkonen 2004-2009.
5 --
6 -- See the included file LICENSE for details.
7 --
8
9 --
10 -- We should really use getloadavg(3) instead and move the meter to
11 -- Ion side to get properly up-to-date loads. But until such an export
12 -- is made, and we use potentially blocking files and external programs, 
13 -- this meter must be in ion-statusd.
14 --
15
16 local defaults={
17     update_interval=10*1000,
18     load_hint="1min",
19     important_threshold=1.5,
20     critical_threshold=4.0
21 }
22
23 local settings=table.join(statusd.get_config("load"), defaults)
24
25 local load_timer
26
27 local function get_hint(v)
28     local i="normal"
29     if v then
30         if v>settings.critical_threshold then
31             i="critical"
32         elseif v>settings.important_threshold then
33             i="important"
34         end
35     end
36     return i
37 end
38
39 local function fmt(l)
40     if not l then
41         return "?"
42     else
43         return string.format("%0.2f", l)
44     end
45 end
46
47 local function update_load()
48     local lds = statusd.getloadavg()
49     f1, f5, f15 = fmt(lds["1min"]), fmt(lds["5min"]), fmt(lds["15min"])
50     statusd.inform("load", f1..", "..f5..", "..f15)
51     statusd.inform("load_hint", get_hint(lds[settings.load_hint]))
52     statusd.inform("load_1min", f1)
53     statusd.inform("load_1min_hint", get_hint(lds["1min"]))
54     statusd.inform("load_5min", f5)
55     statusd.inform("load_5min_hint", get_hint(lds["5min"]))
56     statusd.inform("load_15min", f15)
57     statusd.inform("load_15min_hint", get_hint(lds["15min"]))
58     load_timer:set(settings.update_interval, update_load)
59 end
60
61 -- Init
62 --statusd.inform("load_template", "0.00, 0.00, 0.00");
63
64 load_timer=statusd.create_timer()
65 update_load()
66
67