Class: ScoutApm::Environment
- Inherits:
-
Object
- Object
- ScoutApm::Environment
- Includes:
- Singleton
- Defined in:
- lib/scout_apm/environment.rb
Constant Summary collapse
- STDOUT_LOGGER =
begin l = Logger.new(STDOUT) l.level = Logger::INFO l end
- SERVER_INTEGRATIONS =
I’ve put Thin and Webrick last as they are often used in development and included in Gemfiles but less likely used in production.
[ ScoutApm::ServerIntegrations::Passenger.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Unicorn.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Rainbows.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Puma.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Thin.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Webrick.new(STDOUT_LOGGER), ScoutApm::ServerIntegrations::Null.new(STDOUT_LOGGER), # must be last ]
- BACKGROUND_JOB_INTEGRATIONS =
[ ScoutApm::BackgroundJobIntegrations::Sidekiq.new, # ScoutApm::BackgroundJobIntegrations::DelayedJob.new ]
- FRAMEWORK_INTEGRATIONS =
[ ScoutApm::FrameworkIntegrations::Rails2.new, ScoutApm::FrameworkIntegrations::Rails3Or4.new, ScoutApm::FrameworkIntegrations::Sinatra.new, ScoutApm::FrameworkIntegrations::Ruby.new, # Fallback if none match ]
- PLATFORM_INTEGRATIONS =
[ ScoutApm::PlatformIntegrations::Heroku.new, ScoutApm::PlatformIntegrations::CloudFoundry.new, ScoutApm::PlatformIntegrations::Server.new, ]
- DEPLOY_INTEGRATIONS =
[ ScoutApm::DeployIntegrations::Capistrano3.new(STDOUT_LOGGER), # ScoutApm::DeployIntegrations::Capistrano2.new(STDOUT_LOGGER), ]
Instance Method Summary collapse
-
#app_server ⇒ Object
App server’s name (symbol).
-
#app_server_integration(force = false) ⇒ Object
Returns the whole integration object This needs to be improved.
- #application_name ⇒ Object
- #background_job_integration ⇒ Object
- #background_job_name ⇒ Object
- #database_engine ⇒ Object
- #deploy_integration ⇒ Object
- #deploy_integration? ⇒ Boolean
- #env ⇒ Object
-
#forking? ⇒ Boolean
If forking, don’t start worker thread in the master process.
- #framework ⇒ Object
- #framework_integration ⇒ Object
- #framework_root ⇒ Object
- #hostname ⇒ Object
- #jruby? ⇒ Boolean
- #platform_integration ⇒ Object
- #processors ⇒ Object
- #root ⇒ Object
-
#rubinius? ⇒ Boolean
ruby checks.
- #ruby_187? ⇒ Boolean
- #ruby_19? ⇒ Boolean
- #ruby_2? ⇒ Boolean
-
#sinatra? ⇒ Boolean
framework checks.
Instance Method Details
#app_server ⇒ Object
App server’s name (symbol)
122 123 124 |
# File 'lib/scout_apm/environment.rb', line 122 def app_server app_server_integration.name end |
#app_server_integration(force = false) ⇒ Object
Returns the whole integration object This needs to be improved. Frequently, multiple app servers gem are present and which ever is checked first becomes the designated app server.
Next step: (1) list out all detected app servers (2) install hooks for those that need it (passenger, rainbows, unicorn).
116 117 118 119 |
# File 'lib/scout_apm/environment.rb', line 116 def app_server_integration(force=false) @app_server = nil if force @app_server ||= SERVER_INTEGRATIONS.detect{ |integration| integration.present? } end |
#application_name ⇒ Object
65 66 67 |
# File 'lib/scout_apm/environment.rb', line 65 def application_name Agent.instance.config.value("name") || framework_integration.application_name end |
#background_job_integration ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/scout_apm/environment.rb', line 132 def background_job_integration if Agent.instance.config.value("enable_background_jobs", !Agent.instance.config.config_file_exists?) @background_job_integration ||= BACKGROUND_JOB_INTEGRATIONS.detect {|integration| integration.present?} else nil end end |
#background_job_name ⇒ Object
140 141 142 |
# File 'lib/scout_apm/environment.rb', line 140 def background_job_name background_job_integration && background_job_integration.name end |
#database_engine ⇒ Object
69 70 71 |
# File 'lib/scout_apm/environment.rb', line 69 def database_engine framework_integration.database_engine end |
#deploy_integration ⇒ Object
144 145 146 |
# File 'lib/scout_apm/environment.rb', line 144 def deploy_integration @deploy_integration ||= DEPLOY_INTEGRATIONS.detect{ |integration| integration.present? } end |
#deploy_integration? ⇒ Boolean
148 149 150 |
# File 'lib/scout_apm/environment.rb', line 148 def deploy_integration? !@deploy_integration.nil? end |
#env ⇒ Object
49 50 51 |
# File 'lib/scout_apm/environment.rb', line 49 def env @env ||= deploy_integration? ? deploy_integration.env : framework_integration.env end |
#forking? ⇒ Boolean
If forking, don’t start worker thread in the master process. Since it’s started as a Thread, it won’t survive the fork.
128 129 130 |
# File 'lib/scout_apm/environment.rb', line 128 def forking? app_server_integration.forking? || (background_job_integration && background_job_integration.forking?) end |
#framework ⇒ Object
53 54 55 |
# File 'lib/scout_apm/environment.rb', line 53 def framework framework_integration.name end |
#framework_integration ⇒ Object
57 58 59 |
# File 'lib/scout_apm/environment.rb', line 57 def framework_integration @framework ||= FRAMEWORK_INTEGRATIONS.detect{ |integration| integration.present? } end |
#framework_root ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/scout_apm/environment.rb', line 91 def framework_root if override_root = Agent.instance.config.value("application_root", true) return override_root end if framework == :rails RAILS_ROOT.to_s elsif framework == :rails3_or_4 Rails.root elsif framework == :sinatra Sinatra::Application.root || "." else '.' end end |
#hostname ⇒ Object
106 107 108 109 |
# File 'lib/scout_apm/environment.rb', line 106 def hostname config_hostname = Agent.instance.config.value("hostname", !Agent.instance.config.config_file_exists?) @hostname ||= config_hostname || platform_integration.hostname end |
#jruby? ⇒ Boolean
158 159 160 |
# File 'lib/scout_apm/environment.rb', line 158 def jruby? defined?(JRuby) end |
#platform_integration ⇒ Object
61 62 63 |
# File 'lib/scout_apm/environment.rb', line 61 def platform_integration @platform ||= PLATFORM_INTEGRATIONS.detect{ |integration| integration.present? } end |
#processors ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/scout_apm/environment.rb', line 73 def processors @processors ||= begin proc_file = '/proc/cpuinfo' processors = if !File.exist?(proc_file) 1 else lines = File.read("/proc/cpuinfo").lines.to_a lines.grep(/^processor\s*:/i).size end [processors, 1].compact.max end end |
#root ⇒ Object
86 87 88 89 |
# File 'lib/scout_apm/environment.rb', line 86 def root return deploy_integration.root if deploy_integration framework_root end |
#rubinius? ⇒ Boolean
ruby checks
154 155 156 |
# File 'lib/scout_apm/environment.rb', line 154 def rubinius? RUBY_VERSION =~ /rubinius/i end |
#ruby_187? ⇒ Boolean
166 167 168 |
# File 'lib/scout_apm/environment.rb', line 166 def ruby_187? @ruby_187 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/) end |
#ruby_19? ⇒ Boolean
162 163 164 |
# File 'lib/scout_apm/environment.rb', line 162 def ruby_19? @ruby_19 ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/) end |
#ruby_2? ⇒ Boolean
170 171 172 |
# File 'lib/scout_apm/environment.rb', line 170 def ruby_2? @ruby_2 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^2/) end |
#sinatra? ⇒ Boolean
framework checks
176 177 178 |
# File 'lib/scout_apm/environment.rb', line 176 def sinatra? framework_integration.name == :sinatra end |