Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created January 22, 2009 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrigorik/50360 to your computer and use it in GitHub Desktop.
Save igrigorik/50360 to your computer and use it in GitHub Desktop.
replacement for mysqladmin ext -ri10
# Equivalent to mysqladmin ext -ri10
# - that is, if mysqladmin ext -ri10 works on your box
# - in my case it didn't...
#
# Reports MySQL variable changes for a certain time period
#
# Running: ruby mysql-var-stats.rb interval
require 'rubygems'
require 'ruport'
trap("INT") { exit }
@prev = Hash.new(0)
while true
curr = Hash.new(0)
status = `mysqladmin ext`.split("\n")
status.each do |line|
var = line.split("|")
next if var.size < 2
curr[var[1].strip] = var[2].strip.to_i
end
report = Table(:column_names => ["Variable","Value", "Diff"])
diff = curr.dup.delete_if { |k,v| @prev[k] == v }
diff.each do |key, value|
report << [key, value, curr[key]-@prev[key]]
end
puts report.to_s
puts "\n\n"
@prev = curr
sleep ARGV[0].to_i
end
# Output:
#
# +----------------------------------------------------------+
# | Variable | Value | Diff |
# +----------------------------------------------------------+
# | Handler_read_next | 638727 | 224 |
# | Handler_read_rnd_next | 117140 | 291 |
# | Innodb_data_fsyncs | 77441 | 28 |
# ...
# | Innodb_pages_read | 205017 | 31 |
# | Innodb_buffer_pool_pages_dirty | 81514 | -83 |
# +----------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment