2 -- ion/mod_statusbar/ion-statusd/statusd_load.lua
4 -- Copyright (c) Tuomo Valkonen 2004-2006.
6 -- Ion is free software; you can redistribute it and/or modify it under
7 -- the terms of the GNU Lesser General Public License as published by
8 -- the Free Software Foundation; either version 2.1 of the License, or
9 -- (at your option) any later version.
13 -- We should really use getloadavg(3) instead and move the meter to
14 -- Ion side to get properly up-to-date loads. But until such an export
15 -- is made, and we use potentially blocking files and external programs,
16 -- this meter must be in ion-statusd.
20 update_interval=10*1000,
22 important_threshold=1.5,
23 critical_threshold=4.0
26 local settings=table.join(statusd.get_config("load"), defaults)
28 local loadpat='^(%d+%.%d+).*(%d+%.%d+).*(%d+%.%d+)'
30 local function get_load_proc()
31 local f=io.open('/proc/loadavg', 'r')
37 local st, en, load=string.find(s, '^(%d+%.%d+ %d+%.%d+ %d+%.%d+)')
39 return string.gsub((load or ""), " ", ", ")
42 local function get_load_uptime()
43 local f=io.popen('uptime', 'r')
49 local st, en, load=string.find(s, 'load averages?:%s*(.*)')
53 local function detect_load_fn()
54 if get_load_proc()~="" then
57 return get_load_uptime
61 local get_load, load_timer
63 local function get_hint(l)
67 if v>settings.critical_threshold then
69 elseif v>settings.important_threshold then
76 local l1min, l5min, l15min=2+1, 2+2, 2+3
78 local function update_load()
80 local lds={string.find(l, loadpat)}
81 statusd.inform("load", l)
82 statusd.inform("load_hint", get_hint(lds[settings.load_hint+2]))
83 statusd.inform("load_1min", lds[l1min])
84 statusd.inform("load_1min_hint", get_hint(lds[l1min]))
85 statusd.inform("load_5min", lds[l5min])
86 statusd.inform("load_5min_hint", get_hint(lds[l5min]))
87 statusd.inform("load_15min", lds[l15min])
88 statusd.inform("load_15min_hint", get_hint(lds[l15min]))
89 load_timer:set(settings.update_interval, update_load)
93 --statusd.inform("load_template", "0.00, 0.00, 0.00");
95 get_load=detect_load_fn()
96 load_timer=statusd.create_timer()