2 -- ion/ext_statusbar/ion-statusd/statusd_load.lua
4 -- Copyright (c) Tuomo Valkonen 2004.
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.
23 local function get_load_proc()
24 local f
=io
.open('/proc/loadavg', 'r')
30 local st
, en
, load
=string.find(s
, '^(%d+%.%d+ %d+%.%d+ %d+%.%d+)')
31 return string.gsub((load
or ""), " ", ", ")
34 local function get_load_uptime()
35 local f
=io
.popen('uptime', 'r')
41 local st
, en
, load
=string.find(s
, 'load average:%s*(.*)')
45 local function detect_load_fn()
46 if get_load_proc()~="" then
49 return get_load_uptime
55 local function update_load(timer
)
56 statusd
.inform("load", get_load())
57 timer
:set(settings
.interval
, update_load
)
61 get_load
=detect_load_fn()
62 update_load(statusd
.create_timer())