Class: ProfileIt::Agent
- Inherits:
-
Object
- Object
- ProfileIt::Agent
- Defined in:
- lib/profile_it/agent.rb,
lib/profile_it/agent/logging.rb,
lib/profile_it/agent/reporting.rb
Overview
The agent gathers performance data from a Ruby application. One Agent instance is created per-Ruby process.
Each Agent object creates a worker thread (unless monitoring is disabled or we’re forking). The worker thread wakes up every Agent#period, merges in-memory metrics w/those saved to disk, saves the merged data to disk, and sends it to the profile_it server.
Defined Under Namespace
Constant Summary collapse
- HTTP_HEADERS =
Headers passed up with all API requests.
{ "Agent-Hostname" => Socket.gethostname }
- @@instance =
see self.instance
nil
Constants included from Reporting
Reporting::CA_FILE, Reporting::VERIFY_MODE
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#log_file ⇒ Object
path to the log file.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#metric_lookup ⇒ Object
Hash used to lookup metric ids based on their name and scope.
-
#options ⇒ Object
options passed to the agent when
#start
is called. -
#store ⇒ Object
Accessors below are for associated classes.
Class Method Summary collapse
-
.instance(options = {}) ⇒ Object
All access to the agent is thru this class method to ensure multiple Agent instances are not initialized per-Ruby process.
Instance Method Summary collapse
- #gem_root ⇒ Object
-
#initialize(options = {}) ⇒ Agent
constructor
Note - this doesn’t start instruments or the worker thread.
-
#load_instruments ⇒ Object
Loads the instrumention logic.
-
#start(options = {}) ⇒ Object
This is called via
ProfileIt::Agent.instance.start
when ProfileIt is required in a Ruby application. -
#start_instruments ⇒ Object
Injects instruments into the Ruby application.
- #started? ⇒ Boolean
Methods included from Reporting
#build_http, #checkin_uri, #post, #request, #send_profile
Methods included from Logging
#apply_log_format, #init_logger, #log_level, #log_path
Constructor Details
#initialize(options = {}) ⇒ Agent
Note - this doesn’t start instruments or the worker thread. This is handled via #start
as we don’t want to start the worker thread or install instrumentation if (1) disabled for this environment (2) a worker thread shouldn’t be started (when forking).
31 32 33 34 35 36 37 |
# File 'lib/profile_it/agent.rb', line 31 def initialize( = {}) @started = false @options ||= @store = ProfileIt::Store.new @config = ProfileIt::Config.new([:config_path]) @metric_lookup = Hash.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/profile_it/agent.rb', line 15 def config @config end |
#environment ⇒ Object
Returns the value of attribute environment.
16 17 18 |
# File 'lib/profile_it/agent.rb', line 16 def environment @environment end |
#log_file ⇒ Object
path to the log file
19 20 21 |
# File 'lib/profile_it/agent.rb', line 19 def log_file @log_file end |
#logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/profile_it/agent.rb', line 18 def logger @logger end |
#metric_lookup ⇒ Object
Hash used to lookup metric ids based on their name and scope
21 22 23 |
# File 'lib/profile_it/agent.rb', line 21 def metric_lookup @metric_lookup end |
#options ⇒ Object
options passed to the agent when #start
is called.
20 21 22 |
# File 'lib/profile_it/agent.rb', line 20 def @options end |
#store ⇒ Object
Accessors below are for associated classes
14 15 16 |
# File 'lib/profile_it/agent.rb', line 14 def store @store end |
Class Method Details
.instance(options = {}) ⇒ Object
All access to the agent is thru this class method to ensure multiple Agent instances are not initialized per-Ruby process.
24 25 26 |
# File 'lib/profile_it/agent.rb', line 24 def self.instance( = {}) @@instance ||= self.new() end |
Instance Method Details
#gem_root ⇒ Object
72 73 74 |
# File 'lib/profile_it/agent.rb', line 72 def gem_root File.(File.join("..","..",".."), __FILE__) end |
#load_instruments ⇒ Object
Loads the instrumention logic.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/profile_it/agent.rb', line 77 def load_instruments case environment.framework when :rails require File.(File.join(File.dirname(__FILE__),'instruments/rails/action_controller_instruments.rb')) when :rails3_or_4 require File.(File.join(File.dirname(__FILE__),'instruments/rails3_or_4/action_controller_instruments.rb')) end require File.(File.join(File.dirname(__FILE__),'instruments/active_record_instruments.rb')) require File.(File.join(File.dirname(__FILE__),'instruments/net_http.rb')) require File.(File.join(File.dirname(__FILE__),'instruments/moped_instruments.rb')) require File.(File.join(File.dirname(__FILE__),'instruments/mongoid_instruments.rb')) rescue logger.warn "Exception loading instruments:" logger.warn $!. logger.warn $!.backtrace end |
#start(options = {}) ⇒ Object
This is called via ProfileIt::Agent.instance.start
when ProfileIt is required in a Ruby application. It initializes the agent and starts the worker thread (if appropiate).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/profile_it/agent.rb', line 45 def start( = {}) @options.merge!() init_logger logger.info "Attempting to start profileit.io [#{ProfileIt::VERSION}] on [#{Socket.gethostname}] reporting to #{config.settings['host']}" if !config.settings['profile'] logger.warn "Profiling isn't enabled for the [#{environment.env}] environment." return false elsif !config.settings['key'] logger.warn "The config file doesn't specify an account key. See https://profileit.io/help for a install instructions." return false # elsif !environment.app_server # logger.warn "Couldn't find a supported app server. Not starting agent." # return false elsif started? logger.warn "Already started profileit.io." return false end @started = true logger.info "Starting profiling. Framework [#{environment.framework}] App Server [#{environment.app_server}]." start_instruments logger.info "ProfileIt [#{ProfileIt::VERSION}] Initialized" end |
#start_instruments ⇒ Object
Injects instruments into the Ruby application.
95 96 97 98 |
# File 'lib/profile_it/agent.rb', line 95 def start_instruments logger.debug "Installing instrumentation" load_instruments end |
#started? ⇒ Boolean
68 69 70 |
# File 'lib/profile_it/agent.rb', line 68 def started? @started end |