In the next proxy release we introduce plugins, we talked about it already in MySQL Proxy: a chassis and a mysql server. Take a look at http://svn.mysql.com/svnpublic/mysql-proxy/trunk/plugins/ and check out:
- proxy
- admin
- debug
each of them sharing the common code that is provided by the chassis.
The debug plugin is a lua shell with a mysql-protocol ... well, just read on ;)
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.
Comments