MySQL Proxy: debug plugin

The purpose of the plugin is to be able to introspect the proxy at runtime. If it is loaded you can connect to port 4043 and execute lua code inside the proxy core:

$ mysql --user=root --password=secret --port=4043 --host=192.168.2.113
root@192.168.2.113:4043 [(none)]> return 1;
+------+
| lua  |
+------+
| 1    |
+------+
1 row in set (0.03 sec)

On the command-line this looks to the same:

 $ echo "return 2" | \
    mysql --user=root --password=secret --port=4043 --host=192.168.2.113
 lua
 2

You can also let lua load and execute a file:

$ echo "return assert(loadfile('dump-backends.lua'))()" | \
    mysql --user=root --password=secret --port=4043 --host=192.168.2.113
ERROR 1105 (07000) at line 1: [string "return assert(loadfile('dump-backends.lua')..."]:1: cannot open dump-backends.lua: No such file or directory

Perhaps we should first create the file:

local res = { }

for i = 1, #proxy.global.backends do
    local b = proxy.global.backends[i]

    res[#res + 1] = {
            address = b.address,
            state   = b.state,
            type    = b.type
    }
end

return res

... and execute the script again:

$ echo "return assert(loadfile('dump-backends.lua'))()" | \
    mysql --user=root --password=secret --port=4043 --host=192.168.2.113
state   type    address
0       1       127.0.0.1:3306

As the debug plugin and the proxy plugin share the same lua-scope you can tweak and change parameters in the proxy at runtime. Use it with care.