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