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: :port=>xxx.
- #logger ⇒ Object
- #start_thread ⇒ Object
- #stop_thread! ⇒ Object
Constructor Details
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
68 69 70 |
# File 'lib/scout_realtime/main.rb', line 68 def self.instance(opts={}) @@instance ||= self.new(opts) end |
Instance Method Details
#go_sinatra ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/scout_realtime/main.rb', line 38 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) end |
#go_webrick ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/scout_realtime/main.rb', line 56 def go_webrick logger.info("starting web server ") server = WEBrick::HTTPServer.new(:Port => 5555, :AccessLog => []) server.mount '/', Scout::Realtime::WebServer trap 'INT' do server.shutdown end #start_thread server.start # blocking end |
#logger ⇒ Object
72 73 74 |
# File 'lib/scout_realtime/main.rb', line 72 def logger Scout::Realtime::logger end |
#start_thread ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scout_realtime/main.rb', line 18 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
33 34 35 36 |
# File 'lib/scout_realtime/main.rb', line 33 def stop_thread! logger.info("stopping collector thread") @running=false end |