class SystemMetrics::Instrument::Base
Base
class for System Metric instruments. The default implementations for the methods in this class are all based on a regular expression that is matched against a pattern. Custom intruments that simply need to match against a notfication name can easily extend this class like:
class SearchInstrument < SystemMetrics::Instrument::Base def initialize super /search$/ end end
Attributes
Public Class Methods
Create an instrument that will match notification names on the given pattern.
# File lib/system_metrics/instrument/base.rb, line 20 def initialize(pattern) @pattern = pattern end
Public Instance Methods
Declares whether this instrument handles the given event type.
Please Note: Even if the instrument would ultimately like to ignore the event, it should still return true if it generally handles events like the one passed.
# File lib/system_metrics/instrument/base.rb, line 43 def handles?(event) (event.name =~ pattern) != nil end
Indicates whether the given event should be completely ingored and not collected. This is called only if handles?(event)
returns `true`
# File lib/system_metrics/instrument/base.rb, line 50 def ignore?(event) false end
Holds the mapped paths used in prunning.
# File lib/system_metrics/instrument/base.rb, line 25 def mapped_paths @mapped_paths ||= default_mapped_paths end
Provides an opportunity to modify the event before it's collected and stored. This is where you would normally modify the payload to add, remove, or format its elements.
# File lib/system_metrics/instrument/base.rb, line 57 def prepare(event) # Modify the payload if you care to end
Prune paths based on the mapped paths set.
# File lib/system_metrics/instrument/base.rb, line 30 def prune_path(raw_path) mapped_paths.each do |path, replacement| next unless path.present? raw_path = raw_path.gsub(path, replacement) end raw_path end
Private Instance Methods
# File lib/system_metrics/instrument/base.rb, line 63 def default_mapped_paths # Make Rails.root appear as RAILS_ROOT in pruned paths. paths = { Rails.root.to_s => 'RAILS_ROOT' } # Make Gem paths appear as GEMS_ROOT in pruned paths. Gem.path.each do |path| paths[File.join(path, "gems")] = "GEMS_ROOT" end if defined?(Gem) paths end