Skip to content

Instantly share code, notes, and snippets.

@bradhe
Created March 12, 2014 22:45
Show Gist options
  • Save bradhe/9518123 to your computer and use it in GitHub Desktop.
Save bradhe/9518123 to your computer and use it in GitHub Desktop.
Calculate number of transactions/second being ran against your MySQL DB.
require 'mysql2'
$mysql = Mysql2::Client.new(
host: 'localhost',
username: 'root'
)
SLEEP_TIMEOUT=1.0
last_trx = 0
last_trx_at = Time.now
loop do
result = $mysql.query("show status where Variable_name = 'Queries';")
start_at = Time.now
new_trx = result.first["Value"].to_i
if last_trx > 0
puts '%0.03f' % ((new_trx - last_trx) / (start_at - last_trx_at))
end
last_trx = new_trx
last_trx_at = start_at
sleep(SLEEP_TIMEOUT)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment