Class: PerfMonger::Command::ServerCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- PerfMonger::Command::ServerCommand
- Defined in:
- lib/perfmonger/command/server.rb
Defined Under Namespace
Classes: DashboardServlet, FaucetServlet, Recorder
Instance Method Summary collapse
-
#initialize ⇒ ServerCommand
constructor
A new instance of ServerCommand.
- #parse_args(argv) ⇒ Object
- #run(argv) ⇒ Object
Methods inherited from BaseCommand
register_alias, register_command
Constructor Details
#initialize ⇒ ServerCommand
Returns a new instance of ServerCommand.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/perfmonger/command/server.rb', line 51 def initialize @parser = OptionParser.new @parser. = "Usage: perfmonger server [options] -- [perfmonger record options]\n\nLaunch TCP and HTTP server which enables users to get current\nperfmonger data record via network.\n\nOptions:\n" @hostname = `hostname -f`.strip @http_hostname = nil @http_port = 20202 @tcp_port = 20203 end |
Instance Method Details
#parse_args(argv) ⇒ Object
68 69 70 71 72 73 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 |
# File 'lib/perfmonger/command/server.rb', line 68 def parse_args(argv) @parser.on('-H', '--hostname NAME', "Host name to display (default: #{@hostname})") do |hostname| @hostname = hostname end @parser.on('--http-host NAME', "Host name for HTTP server URL. If not specified, value of '--hostname' option is used.") do |hostname| @http_hostname = hostname end @parser.on('--port PORT', 'HTTP server port to listen.') do |port| if ! port =~ /\A\d+\Z/ puts("ERROR: invalid port number value: #{port}") puts(@parser.help) exit(false) end @http_port = port.to_i end @parser.on('-h', '--help', 'Show this help.') do puts @parser.help exit(false) end # @parser.on('--tcp-port PORT', 'TCP data server port to listen.') do |port| # if ! port =~ /\A\d+\Z/ # puts("ERROR: invalid port number value: #{port}") # puts(@parser.help) # exit(false) # end # @tcp_port = port.to_i # end @parser.parse!(argv) if @http_hostname.nil? @http_hostname = @hostname end @record_cmd_args = argv end |
#run(argv) ⇒ Object
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 |
# File 'lib/perfmonger/command/server.rb', line 110 def run(argv) tmp_rootdir = Dir.mktmpdir parse_args(argv) _, record_option = PerfMonger::Command::RecordOption.parse(@record_cmd_args) # find perfmonger command perfmonger_bin = File.('exe/perfmonger', PerfMonger::ROOTDIR) if ! File.executable?(perfmonger_bin) puts("ERROR: perfmonger not found!") exit(false) end record_cmd = [perfmonger_bin, 'record', *@record_cmd_args] @recorder = Recorder.new(record_cmd).start puts("PerfMonger Realtime Monitor: http://#{@http_hostname}:#{@http_port}/dashboard") puts("") @http_server = WEBrick::HTTPServer.new({:DocumentRoot => tmp_rootdir, :BindAddress => '0.0.0.0', :Port => @http_port}) setup_webrick(@http_server, record_option) trap(:INT) do @http_server.stop @recorder.stop end @http_server.start ensure FileUtils.rm_rf(tmp_rootdir) end |