File: statusd_uptime.lua

package info (click to toggle)
ion3-scripts 20050418-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 300 kB
  • ctags: 153
  • sloc: makefile: 18
file content (45 lines) | stat: -rw-r--r-- 877 bytes parent folder | download
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
-- statusd_uptime.lua
-- 
-- Author
-- Sadrul Habib Chowdhury (Adil)
-- imadil at gmail dot com

--
-- how often should the monitor be updated?
--
local settings={
    interval=30*1000,
}

local timer = nil   -- the timer

--
-- update the uptime monitor
--
local function get_uptime_info()
    local f=io.popen('uptime', 'r')
    timer:set(settings.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()