File: proxyintstats.lua

package info (click to toggle)
memcached 1.6.39-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,320 kB
  • sloc: ansic: 62,281; perl: 12,500; sh: 4,569; makefile: 468; python: 402; xml: 59
file content (74 lines) | stat: -rw-r--r-- 1,848 bytes parent folder | download | duplicates (2)
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
function check_stats(cmd, min)
    local s
    if cmd then
        s = mcp.server_stats(cmd)
    else
        s = mcp.server_stats()
        cmd = "basic"
    end

    local count = 0
    for k, v in pairs(s) do
        count = count + 1
    end

    if min and count < min then
        mcp.log("ERROR: ["..cmd.."] count too low: " .. count)
    else
        mcp.log("SUCCESS: " .. cmd)
    end
end

function check_stats_sections(cmd, minsec, minval)
    local s = mcp.server_stats(cmd)

    local sec = 0
    local val = 0
    for k, v in pairs(s) do
        if type(k) == "number" then
            sec = sec + 1
            for sk, sv in pairs(v) do
                val = val + 1
            end
        else
            -- not a section.
        end
    end

    if minsec and sec < minsec then
        mcp.log("ERROR: ["..cmd.."] section count too low: " .. count)
        return
    end

    if minval and val < minval then
        mcp.log("ERROR: ["..cmd.."] value count too low: " .. count)
        return
    end

    mcp.log("SUCCESS: " .. cmd)
end

function mcp_config_pools()
    -- ensure that ustats print without crash/etc
    mcp.add_stat(1, "foo")
    mcp.add_stat(2, "bar")
    -- delay the stats run by a few seconds since some counters are weird
    -- until initialization completes.
    mcp.register_cron("stats", { every = 2, rerun = false, func = function()
        check_stats(nil, 10)
        check_stats("settings", 10)
        check_stats_sections("conns", 1, 2)
        check_stats("extstore")
        check_stats("proxy", 1)
        check_stats("proxyfuncs", 1)
        check_stats("proxybe")
        check_stats_sections("items", 1, 5)
        check_stats_sections("slabs", 1, 5)
    end })
end

function mcp_config_routes(c)
    mcp.attach(mcp.CMD_ANY_STORAGE, function(r)
        return mcp.internal(r)
    end)
end