lib/redis-stat.rb in redis-stat-0.2.5 vs lib/redis-stat.rb in redis-stat-0.2.6
- old
+ new
@@ -20,10 +20,11 @@
host, port = e.split(':')
Redis.new(Hash[ {:host => host, :port => port}.select { |k, v| v } ])
}
@interval = options[:interval]
@max_count = options[:count]
+ @mono = options[:mono]
@colors = options[:colors] || COLORS
@csv = options[:csv]
@auth = options[:auth]
@measures = MEASURES[ options[:verbose] ? :verbose : :default ]
@count = 0
@@ -47,10 +48,11 @@
r.auth @auth if @auth
end
end
@started_at = Time.now
+ all_measures = MEASURES.values.inject(:+).uniq - [:at]
prev_info = nil
loop do
info = {}.insensitive
class << info
def sumf label
@@ -60,13 +62,13 @@
info[:at] = Time.now.to_f
@redises.pmap(@redises.length) { |redis|
redis.info.insensitive
}.each do |rinfo|
- rinfo.each do |k, v|
+ all_measures.each do |k|
info[k] ||= []
- info[k] << v
+ info[k] << rinfo[k]
end
end
output info, prev_info, csv
@@ -189,31 +191,21 @@
:unicode => false, :align => :right,
:border_style => @style
)
tab << [nil] + @hosts.map { |h| ansi(:bold, :green) { h } }
tab.separator!
- [
- :redis_version,
- :process_id,
- :uptime_in_seconds,
- :uptime_in_days,
- :gcc_version,
- :role,
- :connected_slaves,
- :aof_enabled,
- :vm_enabled
- ].each do |key|
- tab << [ansi(:bold) { key }] + info[key] if info[key]
+ MEASURES[:static].each do |key|
+ tab << [ansi(:bold) { key }] + info[key] unless info[key].compact.empty?
end
@os.puts tab
end
def init_table info_output
table = Tabularize.new :unicode => false,
:align => :right,
:border_style => @style,
- :border_color => ANSI::Code.red,
+ :border_color => @mono ? nil : ANSI::Code.red,
:vborder => ' ',
:pad_left => 0,
:pad_right => 0,
:screen_width => @term_width
table.separator!
@@ -293,17 +285,28 @@
end
return nil
end
def ansi *args, &block
- if args.empty?
+ if @mono || args.empty?
block.call
else
ANSI::Code.ansi *args, &block
end
end
MEASURES = {
+ :static => [
+ :redis_version,
+ :process_id,
+ :uptime_in_seconds,
+ :uptime_in_days,
+ :gcc_version,
+ :role,
+ :connected_slaves,
+ :aof_enabled,
+ :vm_enabled
+ ],
:default => [
:at,
:used_cpu_user,
:used_cpu_sys,
:connected_clients,