MySQL Proxy - Reporter script for admin plugin

Developed In: Lua — Contributed by: Diego Medina

Use with http://forge.mysql.com/tools/tool.php?id=197 to show information using the Admin plugin for the MySQL Proxy


Diego Medina
Lua
  1. --[[
  2.  
  3.   Copyright (C) 2009 MySQL AB, 2008 Sun Microsystems, Inc
  4.  
  5.   This program is free software; you can redistribute it and/or modify
  6.   it under the terms of the GNU General Public License as published by
  7.   the Free Software Foundation; version 2 of the License.
  8.  
  9.   This program is distributed in the hope that it will be useful,
  10.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12.   GNU General Public License for more details.
  13.  
  14.   You should have received a copy of the GNU General Public License
  15.   along with this program; if not, write to the Free Software
  16.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17.  
  18. --]]
  19.  
  20. -- reporter.lua
  21.  
  22. --[[
  23.  
  24.   See http://forge.mysql.com/tools/tool.php?id=78
  25.   (Thanks to Jan Kneschke)
  26.   See http://www.chriscalender.com/?p=41
  27.   (Thanks to Chris Calender)
  28.   See http://datacharmer.blogspot.com/2009/01/mysql-proxy-is-back.html
  29.   (Thanks Giuseppe Maxia)
  30.  
  31. --]]
  32.  
  33. proxy.global.query_counter = proxy.global.query_counter or 0
  34.  
  35. function proxy.global.initialize_process_table()
  36. if proxy.global.process == nil then
  37. proxy.global.process = {}
  38. end
  39. if proxy.global.process[proxy.connection.server.thread_id] == nil then
  40. proxy.global.process[proxy.connection.server.thread_id] = {}
  41. end
  42. end
  43.  
  44. function read_auth_result( auth )
  45. local state = auth.packet:byte()
  46. if state == proxy.MYSQLD_PACKET_OK then
  47. proxy.global.initialize_process_table()
  48. table.insert( proxy.global.process[proxy.connection.server.thread_id],
  49. { ip = proxy.connection.client.src.name, ts = os.time() } )
  50. end
  51. end
  52.  
  53. function disconnect_client()
  54. local connection_id = proxy.connection.server.thread_id
  55. if connection_id then
  56. -- client has disconnected, set this to nil
  57. proxy.global.process[connection_id] = nil
  58. end
  59. end
  60.  
  61.  
  62. ---
  63. -- read_query() can return a resultset
  64. --
  65. -- You can use read_query() to return a result-set.
  66. --
  67. -- @param packet the mysql-packet sent by the client
  68. --
  69. -- @return
  70. -- * nothing to pass on the packet as is,
  71. -- * proxy.PROXY_SEND_QUERY to send the queries from the proxy.queries queue
  72. -- * proxy.PROXY_SEND_RESULT to send your own result-set
  73. --
  74. function read_query( packet )
  75. -- a new query came in in this connection
  76. -- using proxy.global.* to make it available to the admin plugin
  77. proxy.global.query_counter = proxy.global.query_counter + 1
  78.  
  79. end
  80.  

Current Tags

You must be logged in to tag this tool

Thank you for your comments. We will be glad to add Andrew Sadlocha's name to the roster, but we need some kind of proof of his military service in Russia. Photocopies of your grandfather's military records will be enough. Olga Virakhovskaya, Bentley Historical Library Psychology Degree AND online Bachelors degree AND online associate degrees

Eight photos taken by the US Army Corps of Engineers in Pinega during the winter of 1918-1919 can be found here (choose the "Ust Pinega" category). Mike Grobbe online doctorate degree ANDonline Masters degree

Votes

  • Rated 5.00 out of 5
Rated 5.00 out of 5 with 1 votes cast.
You must be logged in to vote.

Watches

2 members are watching this tool
You must be logged in to track this tool.

Provide Feedback

Please note:
HTML will be purified, but we allow for a number of HTML tags so that you have the flexibility to decorate your comment text to some extent. The comments allow the following HTML tags:

strong, b, em, blockquote, a, code, pre

To put code into your comment, simply encapsulate your code with
[code language="XXX"][/code], where XXX is any common language, for instance "PHP", "SQL", "C", etc.



You must be logged in to comment