MySQL Proxy tutorial - Measuring bandwidth by session

Developed In: Lua — Contributed by: Giuseppe Maxia

This script shows how to measure client traffic by session.

MySQL Proxy is a simple program that sits between your client and MySQL server that can monitor, analyze or transform their communication. See http://forge.mysql.com/wiki/MySQL_Proxy for more information.


Giuseppe Maxia
Lua
  1. local bandwidth = 0
  2.  
  3. function read_query (packet )
  4. bandwidth = bandwidth + string.len(packet)
  5. proxy.queries:append(1, packet )
  6. return proxy.PROXY_SEND_QUERY
  7. end
  8.  
  9. function read_query_result(inj)
  10. local fields = inj.resultset.fields
  11. if fields then
  12. for i = 1, #fields do
  13. bandwidth = bandwidth + (fields[i] and fields[i].name:len() or 0)
  14. end
  15. if rows then
  16. for row in inj.resultset.rows do
  17. for i = 1, #inj.resultset.fields do
  18. bandwidth = bandwidth + (row[i] and row[i]:len() or 0)
  19. end
  20. end
  21. end
  22. end
  23. print (proxy.connection.server['thread_id'],bandwidth)
  24. end

Current Tags

You must be logged in to tag this tool

Hey ur post left me quenching for more........ University Accreditation AND engineering education accreditation AND Accreditation

“There has been lots of talk at the Ontario level, but this is the first opportunity that we have had to actually get together and sign a document that affirms our own harvesting rights and the duty to consult with the Crown head to respect our harvesting rights,” he noted. Online university accreditation AND Psychology education accreditation

Votes

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

Watches

0 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