X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils%2Fion-statusd%2Fstatusd_load.lua;fp=utils%2Fion-statusd%2Fstatusd_load.lua;h=88162af1cf8ae1e70be3238b79d9b63b9b495f0b;hb=a6561c9679cd701b0d50c3cfd44e4664f7df2b2f;hp=0000000000000000000000000000000000000000;hpb=cd09055902de482a1be019bf4b4efdae64c98d35;p=ion3.git diff --git a/utils/ion-statusd/statusd_load.lua b/utils/ion-statusd/statusd_load.lua new file mode 100644 index 0000000..88162af --- /dev/null +++ b/utils/ion-statusd/statusd_load.lua @@ -0,0 +1,70 @@ +-- +-- ion/mod_statusbar/ion-statusd/statusd_load.lua +-- +-- Copyright (c) Tuomo Valkonen 2004-2006. +-- +-- Ion is free software; you can redistribute it and/or modify it under +-- the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- + +-- +-- We should really use getloadavg(3) instead and move the meter to +-- Ion side to get properly up-to-date loads. But until such an export +-- is made, and we use potentially blocking files and external programs, +-- this meter must be in ion-statusd. +-- + +local defaults={ + update_interval=10*1000, + load_hint="1min", + important_threshold=1.5, + critical_threshold=4.0 +} + +local settings=table.join(statusd.get_config("load"), defaults) + +local load_timer + +local function get_hint(v) + local i="normal" + if v then + if v>settings.critical_threshold then + i="critical" + elseif v>settings.important_threshold then + i="important" + end + end + return i +end + +local function fmt(l) + if not l then + return "?" + else + return string.format("%0.2f", l) + end +end + +local function update_load() + local lds = statusd.getloadavg() + f1, f5, f15 = fmt(lds["1min"]), fmt(lds["5min"]), fmt(lds["15min"]) + statusd.inform("load", f1..", "..f5..", "..f15) + statusd.inform("load_hint", get_hint(lds[settings.load_hint])) + statusd.inform("load_1min", f1) + statusd.inform("load_1min_hint", get_hint(lds["1min"])) + statusd.inform("load_5min", f5) + statusd.inform("load_5min_hint", get_hint(lds["5min"])) + statusd.inform("load_15min", f15) + statusd.inform("load_15min_hint", get_hint(lds["15min"])) + load_timer:set(settings.update_interval, update_load) +end + +-- Init +--statusd.inform("load_template", "0.00, 0.00, 0.00"); + +load_timer=statusd.create_timer() +update_load() + +