Class: ScoutApm::Environment
- Inherits:
-
Object
- Object
- ScoutApm::Environment
- Includes:
- Singleton
- Defined in:
- lib/scout_apm/environment.rb
Constant Summary collapse
- 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(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Unicorn.new(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Rainbows.new(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Puma.new(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Thin.new(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Webrick.new(Logger.new(STDOUT)), ScoutApm::ServerIntegrations::Null.new(Logger.new(STDOUT)), # must be last ]
- FRAMEWORK_INTEGRATIONS =
[ ScoutApm::FrameworkIntegrations::Rails2.new, ScoutApm::FrameworkIntegrations::Rails3Or4.new, ScoutApm::FrameworkIntegrations::Sinatra.new, ScoutApm::FrameworkIntegrations::Ruby.new, # Fallback if none match ]
Instance Method Summary collapse
-
#app_server ⇒ Object
App server’s name (symbol).
-
#app_server_integration ⇒ Object
Returns the whole integration object This needs to be improved.
- #application_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
- #heroku? ⇒ Boolean
- #hostname ⇒ Object
- #jruby? ⇒ Boolean
- #processors ⇒ Object
- #root ⇒ Object
-
#rubinius? ⇒ Boolean
ruby checks.
- #ruby_187? ⇒ Boolean
- #ruby_19? ⇒ Boolean
-
#sinatra? ⇒ Boolean
framework checks.
Instance Method Details
#app_server ⇒ Object
App server’s name (symbol)
109 110 111 |
# File 'lib/scout_apm/environment.rb', line 109 def app_server app_server_integration.name end |
#app_server_integration ⇒ 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).
104 105 106 |
# File 'lib/scout_apm/environment.rb', line 104 def app_server_integration @app_server = SERVER_INTEGRATIONS.detect{ |integration| integration.present? } end |
#application_name ⇒ Object
39 40 41 |
# File 'lib/scout_apm/environment.rb', line 39 def application_name Agent.instance.config.value("name") || framework_integration.application_name end |
#database_engine ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/scout_apm/environment.rb', line 43 def database_engine default = :mysql if defined?(ActiveRecord::Base) config = ActiveRecord::Base.connection_config if config && config[:adapter] case config[:adapter] when "postgres" then :postgres when "postgresql" then :postgres when "sqlite3" then :sqlite when "mysql" then :mysql else default end else default end else # TODO: Figure out how to detect outside of Rails context. (sequel, ROM, etc) default end end |
#env ⇒ Object
27 28 29 |
# File 'lib/scout_apm/environment.rb', line 27 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.
115 116 117 |
# File 'lib/scout_apm/environment.rb', line 115 def forking? app_server_integration.forking? end |
#framework ⇒ Object
31 32 33 |
# File 'lib/scout_apm/environment.rb', line 31 def framework framework_integration.name end |
#framework_integration ⇒ Object
35 36 37 |
# File 'lib/scout_apm/environment.rb', line 35 def framework_integration @framework ||= FRAMEWORK_INTEGRATIONS.detect{ |integration| integration.present? } end |
#heroku? ⇒ Boolean
90 91 92 |
# File 'lib/scout_apm/environment.rb', line 90 def heroku? ENV['DYNO'] end |
#hostname ⇒ Object
94 95 96 |
# File 'lib/scout_apm/environment.rb', line 94 def hostname @hostname ||= heroku? ? ENV['DYNO'] : Socket.gethostname end |
#jruby? ⇒ Boolean
125 126 127 |
# File 'lib/scout_apm/environment.rb', line 125 def jruby? defined?(JRuby) end |
#processors ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/scout_apm/environment.rb', line 65 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
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scout_apm/environment.rb', line 78 def root if framework == :rails RAILS_ROOT.to_s elsif framework == :rails3_or_4 Rails.root elsif framework == :sinatra Sinatra::Application.root else '.' end end |
#rubinius? ⇒ Boolean
ruby checks
121 122 123 |
# File 'lib/scout_apm/environment.rb', line 121 def rubinius? RUBY_VERSION =~ /rubinius/i end |
#ruby_187? ⇒ Boolean
133 134 135 |
# File 'lib/scout_apm/environment.rb', line 133 def ruby_187? defined?(RUBY_VERSION) && RUBY_VERSION.match(/^1\.8\.7/) end |
#ruby_19? ⇒ Boolean
129 130 131 |
# File 'lib/scout_apm/environment.rb', line 129 def ruby_19? defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION.match(/^1\.9/) end |
#sinatra? ⇒ Boolean
framework checks
139 140 141 |
# File 'lib/scout_apm/environment.rb', line 139 def sinatra? defined?(Sinatra::Application) end |