Skip to content

Instantly share code, notes, and snippets.

@mikeda
Last active December 20, 2015 09:49
Show Gist options
  • Save mikeda/6110454 to your computer and use it in GitHub Desktop.
Save mikeda/6110454 to your computer and use it in GitHub Desktop.
nodetool cfstatsをJSONに変換
#!/usr/local/bin/ruby
require 'json'
result = {}
cur_ks = nil
cur_cf = nil
ARGF.each_line do |line|
line.strip!
if line =~ /^Keyspace: (.+)/
cur_ks = $1
result[cur_ks] ||= {}
elsif line =~ /^Column Family: (.+)/
cur_cf = $1
result[cur_ks]['cf'] ||= {}
result[cur_ks]['cf'][cur_cf] ||= {}
elsif line =~ /^(Read Count|Read Latency|Write Count|Write Latency|Pending Tasks): (.+)/
if result[cur_ks][$1]
result[cur_ks]['cf'][cur_cf][$1] = $2
else
result[cur_ks][$1] = $2
end
elsif line =~ /^(.+): (.+)$/
result[cur_ks]['cf'][cur_cf][$1] = $2
end
end
puts JSON.pretty_generate(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment