Class: Scout::Streamer
- Inherits:
-
Object
- Object
- Scout::Streamer
- Defined in:
- lib/scout/streamer.rb
Constant Summary collapse
- MAX_DURATION =
will shut down automatically after this many seconds
60*30
- SLEEP =
1
Instance Method Summary collapse
-
#initialize(history_file, streaming_key, p_app_id, p_key, p_secret, plugin_ids, system_metric_collectors, hostname, http_proxy, logger = nil) ⇒ Streamer
constructor
-
history_file is the path to the history file * plugin_ids is an array of integers.
-
Constructor Details
#initialize(history_file, streaming_key, p_app_id, p_key, p_secret, plugin_ids, system_metric_collectors, hostname, http_proxy, logger = nil) ⇒ Streamer
-
history_file is the path to the history file
-
plugin_ids is an array of integers
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 |
# File 'lib/scout/streamer.rb', line 12 def initialize(history_file, streaming_key, p_app_id, p_key, p_secret, plugin_ids, system_metric_collectors, hostname, http_proxy, logger = nil) @@continue_streaming = true @history_file = history_file @history = Hash.new @logger = logger @plugin_hashes = [] Pusher.app_id=p_app_id Pusher.key=p_key Pusher.secret=p_secret Pusher.http_proxy = http_proxy if http_proxy !="" #[[:app_id,p_app_id],[:key,p_key],[:secret,p_secret]].each { |p| Pusher.send p.first, p.last} streamer_start_time = Time.now info("Streamer PID=#{$$} starting") # load plugin history load_history # get the array of plugins, AKA the plugin plan @all_plugins = Array(@history["old_plugins"]) info("Starting streamer with key=#{streaming_key} and plugin_ids: #{plugin_ids.inspect}. System metric collectors: #{system_metric_collectors.inspect}. #{@history_file} includes plugin ids #{@all_plugins.map{|p|p['id']}.inspect}. http_proxy = #{http_proxy}") # selected_plugins is subset of the @all_plugins -- those selected in plugin_ids selected_plugins = compile_plugins(@all_plugins, plugin_ids) # main loop. Continue running until global $continue_streaming is set to false OR we've been running for MAX DURATION iteration=1 # use this to log the data at a couple points while(streamer_start_time+MAX_DURATION > Time.now && @@continue_streaming) do plugins = gather_plugin_reports(selected_plugins) system_metric_data = gather_system_metric_reports(system_metric_collectors) bundle={:hostname=>hostname, :server_time=>Time.now.strftime("%I:%M:%S %p"), :server_unixtime => Time.now.to_i, :num_processes=>`ps -e | wc -l`.chomp.to_i, :plugins=>plugins, :system_metrics => system_metric_data} # stream the data via pusherapp begin Pusher[streaming_key].trigger!('server_data', bundle) rescue Pusher::Error => e # (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error) error "Error pushing data: #{e.}" end if iteration == 2 || iteration == 100 info "Run #{iteration} data dump:" info bundle.inspect end sleep(SLEEP) iteration+=1 end info("Streamer PID=#{$$} ending.") # remove the pid file before exiting streamer_pid_file=File.join(File.dirname(history_file),"scout_streamer.pid") File.unlink(streamer_pid_file) if File.exist?(streamer_pid_file) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
Forward Logger methods to an active instance, when there is one.
219 220 221 222 223 224 225 |
# File 'lib/scout/streamer.rb', line 219 def method_missing(meth, *args, &block) if (Logger::SEV_LABEL - %w[ANY]).include? meth.to_s.upcase @logger.send(meth, *args, &block) unless @logger.nil? else super end end |