-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_memcache.lua
97 lines (88 loc) · 2.17 KB
/
check_memcache.lua
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
--
-- Copyright (c) 2009, Cloudkick, Inc.
-- All right reserved.
--
module(..., package.seeall);
local util = require 'util'
local Check = util.Check
local log = util.log
local nicesize = util.nicesize
local io = require 'io'
local function readstats(args)
local mctypes = {uptime=Check.enum.gauge,
time="skip",
version=Check.enum.string,
pointer_size="skip",
rusage_user="skip",
rusage_system="skip",
total_items=Check.enum.gauge,
total_connections=Check.enum.gauge,
cmd_flush=Check.enum.gauge,
cmd_get=Check.enum.gauge,
cmd_set=Check.enum.gauge,
get_hits=Check.enum.gauge,
get_misses=Check.enum.gauge,
get_misses=Check.enum.gauge,
evictions=Check.enum.gauge,
bytes_read=Check.enum.gauge,
bytes_written=Check.enum.gauge}
local client_skt,err = socket.connect(args.ipaddress, args.port)
local r = {}
if client_skt then
client_skt:send("stats\n")
while client_skt ~= nil do
local line, err, partial = client_skt:receive('*l')
if not line and err then
log.crit('Error from memcache. err=%s', err)
error(err)
end
local l = util.split(line)
local cmd = l[1]
if cmd == "END" then
return r
end
if cmd == "ERROR" then
error(line)
end
local t = mctypes[l[2]]
if t == nil then
t = Check.enum.uint64
end
if t ~= "skip" then
r[l[2]] = {l[3], t}
end
end
else
log.crit("Unable to connect to memcached on %s: %s", args.ipaddress, err)
error(err)
end
return r
end
local function getvalue(args)
a = readstats(args)
return a
end
function run(rcheck, args)
if args.ipaddress == nil then
args.ipaddress = '127.0.0.1'
else
args.ipaddress = args.ipaddress[1]
end
if args.port == nil then
args.port = '11211'
else
args.port = args.port[1]
end
local rv, r = pcall(getvalue, args)
print(rv, r)
if rv then
for k,v in pairs(r) do
rcheck:add_metric(k, v[1], v[2])
end
rcheck:set_status('')
else
rcheck:set_error('failed to connect to %s:%s', args.ipaddress, args.port)
log.err("memcache failed err: %s", tostring(r))
end
return rcheck
end