Last active
December 20, 2015 09:49
-
-
Save mikeda/6110454 to your computer and use it in GitHub Desktop.
nodetool cfstatsをJSONに変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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