root/src/modules-lua/noit/module/varnish.lua

Revision a2b666a8ab8d7131bde0c3d600c5f4b8d7fa2709, 1.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

make modules actually be lua modules

  • Property mode set to 100644
Line 
1 -- This connects to a Varnish instance on the management port (8081)
2 -- It issues the stats comment and translates the output into metrics
3
4 module(..., package.seeall)
5
6 function onload(image)
7   print("I'm in varnish onload")
8   return 0
9 end
10
11 function init(module)
12   print("I'm in varnish init")
13   return 0
14 end
15
16 function config(module, options)
17   print("I'm in varnish config")
18   return 0
19 end
20
21 function initiate(module, check)
22   local e = noit.socket()
23   local rv, err = e.connect(check.target, check.config.port or 8081)
24
25   e.write("stats\r\n")
26   str = e.read("\n")
27
28   if rv ~= 0 or not str then
29     check.bad()
30     check.unavailable()
31     check.status(err or str or "unknown error")
32     return
33   end
34
35   local status, len = string.match(str, "^(%d+)%s*(%d+)%s*$")
36   if status then check.available() end
37   -- we want status to be a number
38   status = 0 + status
39   if status ~= 200 then
40     check.bad()
41     check.status(string.format("status %d", status))
42     return
43   end
44
45   local rawstats = e.read(len)
46   local i = 0
47   for v, k in string.gmatch(rawstats, "%s*(%d+)%s+([^\r\n]+)") do
48     k = string.gsub(k, "^%s*", "")
49     k = string.gsub(k, "%s*$", "")
50     k = string.gsub(k, "%s", "_")
51     check.metric_uint32(k,v)
52     i = i + 1
53   end
54   check.status(string.format("%d stats", i))
55   check.good()
56 end
57
Note: See TracBrowser for help on using the browser.