[Email protected] lua]#Cat Admin.lua--[[$%beginlicense%$ Copyright (c), the Oracle and/or its affiliates. All rights reserved. This program was free software; You can redistribute it and/or modify it under the terms of the GNU general public License as published by the free Softwa Re Foundation; Version 2 of the License. This program was distributed in the hope that it'll be useful, but without any WARRANTY; Without even the implied warranty of merchantability or FITNESS for A particular PURPOSE. See the GNU general public License for more details. You should has received a copy of the GNU general public License along and this program; If not, write to the Free Software Foundation, Inc., Wuyi Franklin St, Fifth Floor, Boston, MA 02110-1301 USA $%endlicense% $ --]]functionset_error (errmsg) proxy.response= { type=Proxy. Mysqld_packet_err, ErrMsg= ErrMsgor "Error" }Endfunctionread_query (packet)ifPacket:byte () ~= proxy.com_query ThenSet_error ("[admin] we only handle text-based queries (com_query)") returnProxy. Proxy_send_resultEnd Localquery = Packet:sub (2) Localrows = { } LocalFields = { } ifQuery:lower () = ="SELECT * from Backends" Then Fields={{Name="Backend_ndx", type=Proxy. Mysql_type_long}, {name="Address", type=Proxy. Mysql_type_string}, {name=" State", type=Proxy. Mysql_type_string}, {name="type", type=Proxy. Mysql_type_string}, {name="UUID", type=Proxy. Mysql_type_string}, {name="connected_clients", type=Proxy. Mysql_type_long},} fori =1, #proxy. global.backends Do Localstates = { "Unknown", " up", " Down" } LocalTypes = { "Unknown", "RW", "ro" } Localb =Proxy.global.backends[i] rows[#rows +1] ={i, B.dst.name,--Configured Backend AddressStates[b.state +1],--The C-id is pushed under starting at 0Types[b.type+1],--The C-id is pushed under starting at 0B.uuid,--The MySQL Server ' s UUID if it is managedB.connected_clients--currently connected clients } End ElseIfQuery:lower () = ="SELECT * from Help" Then Fields={{Name="Command", type=Proxy. Mysql_type_string}, {name="Description", type=Proxy. Mysql_type_string},} rows[#rows +1] = {"SELECT * from Help","shows this help"} rows[#rows +1] = {"SELECT * from Backends","lists the backends and their state" } ElseSet_error ("Use ' SELECT * from help ' to see the supported commands") returnProxy. Proxy_send_resultEndProxy.response= { type=Proxy. MYSQLD_PACKET_OK, ResultSet={ fields=Fields , Rows=rows}} returnProxy. Proxy_send_resultEnd
The Admin-lua-script in Mysql-proxy