# encoding: utf-8 module OneApm class EnvironmentReport def self.report_on(key, &block) registered_reporters[key] = block end def self.registered_reporters @registered_reporters ||= Hash.new end def self.registered_reporters=(logic) @registered_reporters = logic end report_on('Gems') do begin Bundler.rubygems.all_specs.map { |_gem| "#{_gem.name}(#{_gem.version})" } rescue Bundler.load.specs.map do |spec| version = (spec.respond_to?(:version) && spec.version) spec.name + (version ? "(#{version})" : "") end end end report_on('Plugin List' ) { ::Rails.configuration.plugins.to_a } report_on('Ruby version' ) { RUBY_VERSION } report_on('Ruby description' ) { RUBY_DESCRIPTION } report_on('Ruby platform' ) { RUBY_PLATFORM } report_on('Ruby patchlevel' ) { RUBY_PATCHLEVEL.to_s } report_on('JRuby version' ) { JRUBY_VERSION } report_on('Java VM version' ) { ENV_JAVA['java.vm.version'] } report_on('Logical Processors') { OneApm::Support::SystemInfo.num_logical_processors } report_on('Physical Cores' ) { OneApm::Support::SystemInfo.num_physical_cores } report_on('Arch' ) { OneApm::Support::SystemInfo.processor_arch } report_on('OS version' ) { OneApm::Support::SystemInfo.os_version } report_on('OS' ) { OneApm::Support::SystemInfo.ruby_os_identifier } report_on('Database adapter' ) do ActiveRecord::Base.configurations[OneApm::Probe.instance.env]['adapter'] end report_on('Framework' ) { OneApm::Manager.config[:framework].to_s } report_on('Dispatcher' ) { OneApm::Manager.config[:dispatcher].to_s } report_on('Environment' ) { OneApm::Probe.instance.env } report_on('Rails version' ) { ::Rails::VERSION::STRING } report_on('Rails threadsafe') do ::Rails.configuration.action_controller.allow_concurrency end report_on('Rails Env') do if defined? ::Rails and ::Rails.respond_to?(:env) ::Rails.env.to_s else ENV['RAILS_ENV'] end end attr_reader :data def initialize @data = self.class.registered_reporters.inject(Hash.new) do |data, (key, logic)| begin value = logic.call if value data[key] = value OneApm::Manager.record_metric("Supportability/EnvironmentReport/success", 0.0) OneApm::Manager.record_metric("Supportability/EnvironmentReport/success/#{key}", 0.0) else OneApm::Manager.logger.debug("EnvironmentReport ignoring value for #{key.inspect} which came back falsey: #{value.inspect}") OneApm::Manager.record_metric("Supportability/EnvironmentReport/empty", 0.0) OneApm::Manager.record_metric("Supportability/EnvironmentReport/empty/#{key}", 0.0) end rescue => e OneApm::Manager.logger.debug("EnvironmentReport failed to retrieve value for #{key.inspect}: #{e}") OneApm::Manager.record_metric("Supportability/EnvironmentReport/error", 0.0) OneApm::Manager.record_metric("Supportability/EnvironmentReport/error/#{key}", 0.0) end data end end def [](key) @data[key] end def []=(key, value) @data[key] = value end def to_a @data.to_a end end end