1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
-- Authors: Sadrul Habib Chowdhury <imadil@gmail.com>
-- License: Public domain
-- Last Changed: Unknown
--
-- statusd_uptime.lua
--
-- Author
-- Sadrul Habib Chowdhury (Adil)
-- imadil at gmail dot com
--
-- how often should the monitor be updated?
--
if not statusd_uptime then
statusd_uptime={
interval=30*1000,
}
end
local timer = nil -- the timer
--
-- update the uptime monitor
--
local function get_uptime_info()
local f=io.popen('uptime', 'r')
timer:set(statusd_uptime.interval, get_uptime_info)
if not f then
statusd.inform("uptime", "oops")
return
end
local s=f:read('*line')
f:close()
s = string.gsub(s, ", +%d+ user.+", "") -- unnecessary
s = string.gsub(s, "%d+:%d+:%d+ up +", "") -- time is unnecessary
statusd.inform("uptime", s)
end
--
-- start the timer
--
local function init_uptime_monitor()
timer = statusd.create_timer()
statusd.inform("uptime_template", "xxxxxxxxxxxxxxx")
get_uptime_info()
end
init_uptime_monitor()
|