lib/redis-stat.rb in redis-stat-0.4.12-java vs lib/redis-stat.rb in redis-stat-0.4.13
- old
+ new
@@ -26,22 +26,24 @@
Ansi256.enabled = STDOUT.tty? && !(windows || options[:mono])
options[:style] = :ascii if windows
@hosts = options[:hosts]
@interval = options[:interval]
+ @auth = options[:auth]
@redises = @hosts.inject({}) { |hash, e|
- host, port = e.split(':')
+ hostport, password = e.split('/')
+ host, port = hostport.split(':')
hash[e] = Redis.new(Hash[ {:host => host,
:port => port,
+ :password => password || @auth,
:timeout => @interval}.select { |k, v| v } ])
hash
}
@max_count = options[:count]
@colors = options[:colors] || COLORS
@csv_file = options[:csv_file]
@csv_output = options[:csv_output]
- @auth = options[:auth]
@verbose = options[:verbose]
@measures = MEASURES[ @verbose ? :verbose : :default ].map { |m| [*m].first }
@tab_measures = MEASURES[:static].map { |m| [*m].first }
@all_measures = TYPES.keys
@count = 0
@@ -80,11 +82,10 @@
File.open(File.expand_path(@csv_file), 'w')
elsif @csv_output
$stdout
end
update_term_size!
- authenticate!
# Initial info collection
info, x = collect
unless x.empty?
output_term_errors! format_exceptions(x)
@@ -112,15 +113,10 @@
collect
rescue Interrupt
raise
end
- if exceptions.any? { |k, v| need_auth? v }
- authenticate!
- next
- end
-
info_output_all = process info, prev_info
begin
output_es Hash[info_output_all] if @elasticsearch && @count > 0
rescue Interrupt
raise
@@ -457,11 +453,11 @@
sum + Hash[ vs.split(',').map { |e| e.split '=' } ]['keys'].to_i
}
})
[humanize_number(val), val]
when :evicted_keys_per_second, :expired_keys_per_second, :keyspace_hits_per_second,
- :keyspace_misses_per_second, :total_commands_processed_per_second
+ :keyspace_misses_per_second, :total_commands_processed_per_second, :rejected_connections_per_second
val = get_diff.call(key.to_s.gsub(/_per_second$/, '').to_sym)
[humanize_number(val), val]
when :used_memory, :used_memory_rss, :aof_current_size, :aof_base_size
val = info.f(host, key)
[humanize_number(val.to_i, true), val]
@@ -505,18 +501,7 @@
def colorize str, *colors
colors.each do |color|
str = str.send color
end
str
- end
-
- def need_auth? e
- @auth && e.is_a?(Redis::CommandError) &&
- e.to_s =~ /NOAUTH|operation not permitted/
- end
-
- def authenticate!
- @redises.values.each do |r|
- r.ping rescue (r.auth @auth)
- end if @auth
end
end