-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_psaux.lua
More file actions
38 lines (34 loc) · 835 Bytes
/
check_psaux.lua
File metadata and controls
38 lines (34 loc) · 835 Bytes
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
--
-- Copyright (c) 2009, Cloudkick, Inc.
-- All right reserved.
--
module(..., package.seeall);
local io = require 'io'
local util = require 'util'
local Check = util.Check
local log = util.log
local structs = require 'structs'
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
local function getvalue(args)
local rv = 0
return os.capture('ps aux', true)
end
function run(rcheck, args)
local rv, value = pcall(getvalue, args)
if rv then
rcheck:add_metric('output', value, Check.enum.string)
else
log.err("err from psaux: %s", tostring(value))
rcheck:set_error("%s", value)
end
return rcheck
end