class Flare::Tools::Cli::Threads

Public Class Methods

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

Public Instance Methods

execute(config, args) click to toggle source
# File lib/flare/tools/cli/threads.rb, line 32
def execute(config, args)
  parse_index_server(config, args)
  header = [
            ['%5s', 'id'],
            ['%-32s', 'peer'],
            ['%-13s', 'operation'],
            ['%4s', 'type'],
            ['%8s', 'queue']
           ]
  format = header.map {|x| x[0]}.join(' ')

  hostname = config[:index_server_hostname]
  port = config[:index_server_port]

  if args.size == 1
    nodekey = nodekey_of args[0]
    if nodekey.nil?
      error "invalid nodekey: "+args[0]
      return S_NG
    end
    hostname, port = nodekey.split(':')
  elsif args.size > 1
    error "invalid arguments: "+args.join(' ')
    return S_NG
  end

  threads = []

  Flare::Tools::Stats.open(hostname, port, @timeout) do |s|
    threads = s.stats_threads
    threads = threads.sort_by{|key,val| [val['peer'], key]}
  end

  puts format % header.map{|x| x[1]}.flatten

  threads.each do |thread_id, data|
    puts format % [
                   thread_id,
                   data['peer'],
                   if data['op'].nil? then "-" else data['op'] end,
                   data['type'],
                   data['queue'],
                  ]
  end

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