class Flare::Tools::Cli::Summary

Constants

HeaderConfig

Public Class Methods

new() click to toggle source
Calls superclass method Flare::Tools::Cli::SubCommand::new
# File lib/flare/tools/cli/summary.rb, line 39
def initialize
  super
end

Public Instance Methods

execute(config, args) click to toggle source
# File lib/flare/tools/cli/summary.rb, line 43
def execute(config, args)
  parse_index_server(config, args)
  nodes = {}
  threads = {}
  header = HeaderConfig

  Flare::Tools::IndexServer.open(config[:index_server_hostname], config[:index_server_port], @timeout) do |s|
    nodes = s.stats_nodes
    unless nodes
      error "Invalid index server."
      return S_NG
    end
    nodes = nodes.sort_by{|key,val| [val['partition'].to_i, val['role'], key]}
  end

  name = if config[:cluster].nil? then
           "#{config[:index_server_hostname]}:#{config[:index_server_port]}"
         else
           config[:cluster]
         end

  total_bytes = 0
  total_parts = 0
  total_nodes = 0
  total_items = 0
  total_masters = 0
  total_slaves = 0

  nodes.each do |hostname_port,data|
    hostname, port = hostname_port.split(":", 2)
    Flare::Tools::Stats.open(hostname, data['port'], @timeout) do |s|
      stats = s.stats
      p = data['partition'].to_i
      total_parts = p+1 if p+1 > total_parts if data['role'] == 'master'
      total_nodes += 1
      total_masters += 1 if data['role'] == 'master'
      total_slaves += 1 if data['role'] == 'slave'
      total_bytes += stats['bytes'].to_i if data['role'] == 'master'
      total_items += stats['curr_items'].to_i if data['role'] == 'master'
    end
  end

  format = header.map {|x| x[0]}.join(@delimiter)
  label = format % header.map{|x| x[1]}.flatten
  puts label
  puts(format % [name, total_parts, total_nodes, total_masters, total_slaves, total_bytes, total_items])

  S_OK
end
setup() click to toggle source
Calls superclass method Flare::Tools::Cli::SubCommand#setup
# File lib/flare/tools/cli/summary.rb, line 34
def setup
  super
  set_option_index_server
end