In the Enterprise Team we had the need to track how many connections to the MySQL server in parallel. By "used" I mean running queries and not just idling around.
And to make it more complicated we needed the information not
just every few seconds (while true; do echo "SHOW
PROCESSLIST" | mysql; sleep 1;done) but when it happens.
Proxy to the rescue we now have a script which tracks the global
state of all connections going through the proxy and dump them to
stdout when their state changes:
2007-08-28 21:39:55 #connections: 20, #active trx: 3, max(active trx): 4 [792] (merlin@merlin) (COM_QUERY) "SET autocommit=0" (state=started) [794] (merlin@merlin) (COM_QUERY) "SET autocommit=1" (state=started) [795] (merlin@merlin) (COM_QUERY) "SET autocommit=1" (state=started)
- when the query comes in, we add it with its thread-id to the global table
- when the query is done, we track …