Class: Flare::Tools::Cli::Threads

Inherits:
SubCommand show all
Includes:
IndexServerConfig, Flare::Tools::Common, Util::Conversion
Defined in:
lib/flare/tools/cli/threads.rb

Constant Summary

Constants included from IndexServerConfig

IndexServerConfig::Entity, IndexServerConfig::FLARE_INDEX_SERVER, IndexServerConfig::FLARE_INDEX_SERVERS

Constants included from Util::Constant

Util::Constant::DefalutBwlimit, Util::Constant::DefaultIndexServerName, Util::Constant::DefaultIndexServerPort, Util::Constant::DefaultNodePort, Util::Constant::DefaultTimeout, Util::Constant::STATUS_NG, Util::Constant::STATUS_OK

Constants included from Flare::Tools::Common

Flare::Tools::Common::NodeListFormat, Flare::Tools::Common::NodeListHeader

Constants inherited from SubCommand

SubCommand::S_NG, SubCommand::S_OK

Constants included from Util::Interruption

Util::Interruption::InterruptionTargets

Instance Attribute Summary

Attributes included from Option

#optp

Instance Method Summary collapse

Methods included from Util::Logging

#debug, #error, #fatal, #info, logger, #puts, set_logger, #trace, #warn

Methods included from Flare::Tools::Common

#address_of_hostname, #fetch_cluster, #hostname_of_address, #nodekey_of, #string_of_nodelist, #user_confirmed, #wait_for_master_construction, #wait_for_servers, #wait_for_slave_construction

Methods included from Util::Conversion

#short_desc_of_second

Methods inherited from SubCommand

desc, #execute_subcommand, myname, #myname, to_s, to_sym, usage

Methods included from Util::Interruption

included, #initialize_interruption, #interrupt, #interrupt_, interrupt_all, #interrupted?, #interruptible, #interruptible?

Methods included from Option

#option_init, #parse_options, #set_option_dry_run, #set_option_force, #set_option_global, #set_option_index_server

Constructor Details

#initializeThreads

Returns a new instance of Threads.



29
30
31
# File 'lib/flare/tools/cli/threads.rb', line 29

def initialize
  super
end

Instance Method Details

#execute(config, args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/flare/tools/cli/threads.rb', line 33

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

#setupObject



24
25
26
27
# File 'lib/flare/tools/cli/threads.rb', line 24

def setup
  super
  set_option_index_server
end