Class: Scout::Realtime::Main
Constant Summary collapse
- INTERVAL =
time in seconds between runs of the thread to fetch stats
3
- TTL =
time in seconds for collectors to cache slow system commands
60
- LOG_NAME =
"realtime.log"
Instance Attribute Summary collapse
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#running ⇒ Object
Returns the value of attribute running.
-
#stats_thread ⇒ Object
Returns the value of attribute stats_thread.
Class Method Summary collapse
-
.instance(opts = {}) ⇒ Object
singleton.
Instance Method Summary collapse
- #go_sinatra ⇒ Object
- #go_webrick ⇒ Object
-
#initialize(opts = {}) ⇒ Main
constructor
opts: bind=>‘0.0.0.0’.
- #logger ⇒ Object
- #start_thread ⇒ Object
- #stop_thread! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Main
opts: bind=>‘0.0.0.0’
11 12 13 14 15 16 17 |
# File 'lib/scout_realtime/main.rb', line 11 def initialize(opts={}) @port=opts[:port] @bind_address=opts[:bind] || '0.0.0.0' Scout::Realtime::logger=Logger.new(STDOUT) @stats_thread = Thread.new {} @runner = Scout::Realtime::Runner.new end |
Instance Attribute Details
#runner ⇒ Object
Returns the value of attribute runner.
8 9 10 |
# File 'lib/scout_realtime/main.rb', line 8 def runner @runner end |
#running ⇒ Object
Returns the value of attribute running.
8 9 10 |
# File 'lib/scout_realtime/main.rb', line 8 def running @running end |
#stats_thread ⇒ Object
Returns the value of attribute stats_thread.
8 9 10 |
# File 'lib/scout_realtime/main.rb', line 8 def stats_thread @stats_thread end |
Class Method Details
.instance(opts = {}) ⇒ Object
singleton
69 70 71 |
# File 'lib/scout_realtime/main.rb', line 69 def self.instance(opts={}) @@instance ||= self.new(opts) end |
Instance Method Details
#go_sinatra ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scout_realtime/main.rb', line 39 def go_sinatra #@runner.run # sets up the latest_run so we can use it to render the main page #@runner.latest_run=DATA_FOR_TESTING.first logger.info("starting web server ") #['INT', 'TERM'].each do |signal| # trap signal do # puts "got a #{signal} signal -- shutting down :)" # @stats_thread.exit # #Scout::Realtime::WebApp.quit! # # end #end start_thread Scout::Realtime::WebApp.run!(:port=>@port,:bind=>@bind_address) end |
#go_webrick ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/scout_realtime/main.rb', line 57 def go_webrick logger.info("starting web server ") server = WEBrick::HTTPServer.new(:Port => @port, :AccessLog => [], :BindAddress => @bind_address) server.mount '/', Scout::Realtime::WebServer trap 'INT' do server.shutdown end #start_thread server.start # blocking end |
#logger ⇒ Object
73 74 75 |
# File 'lib/scout_realtime/main.rb', line 73 def logger Scout::Realtime::logger end |
#start_thread ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/scout_realtime/main.rb', line 19 def start_thread return if @running logger.info("starting stats collector thread") @running = true @stats_thread = Thread.new do while (@running) do @runner.run logger.info("collector thread run ##{@runner.num_runs} ") if @runner.num_runs.to_f % 50.0 == 2 || @runner.num_runs == 1 sleep INTERVAL end end @stats_thread.abort_on_exception = true end |
#stop_thread! ⇒ Object
34 35 36 37 |
# File 'lib/scout_realtime/main.rb', line 34 def stop_thread! logger.info("stopping collector thread") @running=false end |