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::Resque.new, 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, ]
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
- #env ⇒ Object
-
#forking? ⇒ Boolean
If forking, don’t start worker thread in the master process.
- #framework ⇒ Object
- #framework_integration ⇒ Object
- #framework_root ⇒ Object
- #git_revision ⇒ Object
- #hostname ⇒ Object
-
#interactive? ⇒ Boolean
If both stdin & stdout are interactive and the Rails::Console constant is defined.
- #jruby? ⇒ Boolean
-
#os ⇒ Object
Returns a string representation of the OS (ex: darwin, linux).
- #platform_integration ⇒ Object
- #processors ⇒ Object
- #raw_database_adapter ⇒ Object
- #root ⇒ Object
-
#rubinius? ⇒ Boolean
ruby checks.
- #ruby_187? ⇒ Boolean
- #ruby_19? ⇒ Boolean
- #ruby_2? ⇒ Boolean
- #scm_subdirectory ⇒ Object
-
#sinatra? ⇒ Boolean
framework checks.
Instance Method Details
#app_server ⇒ Object
App server’s name (symbol)
134 135 136 |
# File 'lib/scout_apm/environment.rb', line 134 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).
128 129 130 131 |
# File 'lib/scout_apm/environment.rb', line 128 def app_server_integration(force=false) @app_server = nil if force @app_server ||= SERVER_INTEGRATIONS.detect{ |integration| integration.present? } end |
#application_name ⇒ Object
61 62 63 64 65 |
# File 'lib/scout_apm/environment.rb', line 61 def application_name Agent.instance.config.value("name") || framework_integration.application_name || "App" end |
#background_job_integration ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/scout_apm/environment.rb', line 144 def background_job_integration if Agent.instance.config.value("enable_background_jobs") @background_job_integration ||= BACKGROUND_JOB_INTEGRATIONS.detect {|integration| integration.present?} else nil end end |
#background_job_name ⇒ Object
152 153 154 |
# File 'lib/scout_apm/environment.rb', line 152 def background_job_name background_job_integration && background_job_integration.name end |
#database_engine ⇒ Object
67 68 69 |
# File 'lib/scout_apm/environment.rb', line 67 def database_engine framework_integration.database_engine end |
#env ⇒ Object
45 46 47 |
# File 'lib/scout_apm/environment.rb', line 45 def env @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.
140 141 142 |
# File 'lib/scout_apm/environment.rb', line 140 def forking? app_server_integration.forking? || (background_job_integration && background_job_integration.forking?) end |
#framework ⇒ Object
49 50 51 |
# File 'lib/scout_apm/environment.rb', line 49 def framework framework_integration.name end |
#framework_integration ⇒ Object
53 54 55 |
# File 'lib/scout_apm/environment.rb', line 53 def framework_integration @framework ||= FRAMEWORK_INTEGRATIONS.detect{ |integration| integration.present? } end |
#framework_root ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/scout_apm/environment.rb', line 100 def framework_root if override_root = Agent.instance.config.value("application_root") 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 |
#git_revision ⇒ Object
119 120 121 |
# File 'lib/scout_apm/environment.rb', line 119 def git_revision @git_revision ||= ScoutApm::GitRevision.new end |
#hostname ⇒ Object
115 116 117 |
# File 'lib/scout_apm/environment.rb', line 115 def hostname @hostname ||= Agent.instance.config.value("hostname") || platform_integration.hostname end |
#interactive? ⇒ Boolean
If both stdin & stdout are interactive and the Rails::Console constant is defined
157 158 159 |
# File 'lib/scout_apm/environment.rb', line 157 def interactive? defined?(::Rails::Console) && $stdout.isatty && $stdin.isatty end |
#jruby? ⇒ Boolean
167 168 169 |
# File 'lib/scout_apm/environment.rb', line 167 def jruby? defined?(JRuby) end |
#os ⇒ Object
Returns a string representation of the OS (ex: darwin, linux)
184 185 186 187 188 189 190 191 192 193 |
# File 'lib/scout_apm/environment.rb', line 184 def os return @os if @os raw_os = RbConfig::CONFIG['target_os'] match = raw_os.match(/([a-z]+)/) if match @os = match[1] else @os = raw_os end end |
#platform_integration ⇒ Object
57 58 59 |
# File 'lib/scout_apm/environment.rb', line 57 def platform_integration @platform ||= PLATFORM_INTEGRATIONS.detect{ |integration| integration.present? } end |
#processors ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/scout_apm/environment.rb', line 75 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 |
#raw_database_adapter ⇒ Object
71 72 73 |
# File 'lib/scout_apm/environment.rb', line 71 def raw_database_adapter framework_integration.raw_database_adapter end |
#root ⇒ Object
96 97 98 |
# File 'lib/scout_apm/environment.rb', line 96 def root @root ||= framework_root end |
#rubinius? ⇒ Boolean
ruby checks
163 164 165 |
# File 'lib/scout_apm/environment.rb', line 163 def rubinius? RUBY_VERSION =~ /rubinius/i end |
#ruby_187? ⇒ Boolean
175 176 177 |
# File 'lib/scout_apm/environment.rb', line 175 def ruby_187? @ruby_187 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/) end |
#ruby_19? ⇒ Boolean
171 172 173 |
# File 'lib/scout_apm/environment.rb', line 171 def ruby_19? @ruby_19 ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/) end |
#ruby_2? ⇒ Boolean
179 180 181 |
# File 'lib/scout_apm/environment.rb', line 179 def ruby_2? @ruby_2 ||= defined?(RUBY_VERSION) && RUBY_VERSION.match(/^2/) end |
#scm_subdirectory ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/scout_apm/environment.rb', line 88 def scm_subdirectory @scm_subdirectory ||= if Agent.instance.config.value('scm_subdirectory').empty? '' else Agent.instance.config.value('scm_subdirectory').sub(/^\//, '') # Trim any leading slash end end |
#sinatra? ⇒ Boolean
framework checks
197 198 199 |
# File 'lib/scout_apm/environment.rb', line 197 def sinatra? framework_integration.name == :sinatra end |