Class: Flare::Tools::Cli::Stats
- Inherits:
-
SubCommand
- Object
- SubCommand
- Flare::Tools::Cli::Stats
- Includes:
- IndexServerConfig, Flare::Tools::Common, Util::Conversion, Util::Logging, Util::PrettyTable
- Defined in:
- lib/flare/tools/cli/stats.rb
Overview
Description
Constant Summary collapse
- HeaderConfigs =
[ ['hostname:port', {}], ['state', {}], ['role', {}], ['partition', {:align => :right}], ['balance', {:align => :right}], ['items', {:align => :right}], ['conn', {:align => :right}], ['behind', {:align => :right}], ['hit', {:align => :right}], ['size', {:align => :right}], ['uptime', {:align => :right}], ['version', {:align => :right}], ]
- HeaderConfigQpss =
[ ['qps', {:align => :right}], ['qps-r', {:align => :right}], ['qps-w', {:align => :right}], ]
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
Flare::Tools::Cli::SubCommand::S_NG, Flare::Tools::Cli::SubCommand::S_OK
Constants included from Util::Interruption
Util::Interruption::InterruptionTargets
Instance Attribute Summary
Attributes included from Option
Instance Method Summary collapse
- #execute(config, args) ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #interrupt ⇒ Object
- #setup ⇒ Object
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
Methods inherited from SubCommand
desc, #execute_subcommand, myname, #myname, to_s, to_sym, usage
Methods included from Util::Interruption
included, #initialize_interruption, #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
#initialize ⇒ Stats
Returns a new instance of Stats.
60 61 62 63 64 65 66 67 |
# File 'lib/flare/tools/cli/stats.rb', line 60 def initialize super @qps = false @wait = 1 @count = 1 @cont = true @delimiter = ' ' end |
Instance Method Details
#execute(config, args) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/flare/tools/cli/stats.rb', line 74 def execute(config, args) parse_index_server(config, args) nodes = {} threads = {} 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]} threads = s.stats_threads_by_peer end worker_threads = [] queue = {} nodes.each do |hostname_port,data| queue[hostname_port] = SizedQueue.new(1) worker_threads << Thread.new(queue[hostname_port]) do |q| enqueueing_node_stats(q, threads, config, hostname_port, data) end end query_prev = {} if @qps if @count > 1 || @qps interruptible {sleep 1} end s = Flare::Tools::IndexServer.open( @index_server_entity.host, @index_server_entity.port, @timeout ) unless s error "Couldn't connect to the index server." return S_NG end (0...@count).each do |i| nodes = s.stats_nodes unless nodes error "Invalid index server." exit 1 end nodes = nodes.sort_by{|key,val| [val['partition'].to_i, val['role'], key]} threads = s.stats_threads_by_peer break unless @cont max_nodekey_length = 25 nodes.each do |k, n| max_nodekey_length = k.length if k.length > max_nodekey_length end r = records(args, nodes, queue, threads, query_prev) interruptible { wait_for_stats } table = Table.new add_header_to_table(table, header_configs) add_records_to_table(table, header_configs, r) puts table.prettify end s.close @cont = false queue.each do |k,q| q.pop until q.empty? end interruptible { worker_threads.each do |t| t.join end } S_OK end |
#interrupt ⇒ Object
69 70 71 72 |
# File 'lib/flare/tools/cli/stats.rb', line 69 def interrupt puts "INTERRUPTED" @cont = false end |
#setup ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/flare/tools/cli/stats.rb', line 51 def setup super set_option_index_server @optp.on("-q", '--qps', "show qps") {|v| @qps = v} @optp.on("-w", '--wait=SECOND', "specify wait time for repeat(second)") {|v| @wait = v.to_i} @optp.on("-c", '--count=REPEATTIME', "specify repeat count") {|v| @count = v.to_i} @optp.on("-d", '--delimiter=CHAR', "specify delimiter") {|v| @delimiter = v} end |