1function check_stats(cmd, min)
2    local s
3    if cmd then
4        s = mcp.server_stats(cmd)
5    else
6        s = mcp.server_stats()
7        cmd = "basic"
8    end
9
10    local count = 0
11    for k, v in pairs(s) do
12        count = count + 1
13    end
14
15    if min and count < min then
16        mcp.log("ERROR: ["..cmd.."] count too low: " .. count)
17    else
18        mcp.log("SUCCESS: " .. cmd)
19    end
20end
21
22function check_stats_sections(cmd, minsec, minval)
23    local s = mcp.server_stats(cmd)
24
25    local sec = 0
26    local val = 0
27    for k, v in pairs(s) do
28        if type(k) == "number" then
29            sec = sec + 1
30            for sk, sv in pairs(v) do
31                val = val + 1
32            end
33        else
34            -- not a section.
35        end
36    end
37
38    if minsec and sec < minsec then
39        mcp.log("ERROR: ["..cmd.."] section count too low: " .. count)
40        return
41    end
42
43    if minval and val < minval then
44        mcp.log("ERROR: ["..cmd.."] value count too low: " .. count)
45        return
46    end
47
48    mcp.log("SUCCESS: " .. cmd)
49end
50
51function mcp_config_pools()
52    -- ensure that ustats print without crash/etc
53    mcp.add_stat(1, "foo")
54    mcp.add_stat(2, "bar")
55    -- delay the stats run by a few seconds since some counters are weird
56    -- until initialization completes.
57    mcp.register_cron("stats", { every = 2, rerun = false, func = function()
58        check_stats(nil, 10)
59        check_stats("settings", 10)
60        check_stats_sections("conns", 1, 2)
61        check_stats("extstore")
62        check_stats("proxy", 1)
63        check_stats("proxyfuncs", 1)
64        check_stats("proxybe")
65        check_stats_sections("items", 1, 5)
66        check_stats_sections("slabs", 1, 5)
67    end })
68end
69
70function mcp_config_routes(c)
71    mcp.attach(mcp.CMD_ANY_STORAGE, function(r)
72        return mcp.internal(r)
73    end)
74end
75