Sha256: 54dcab5437a8368969e6d6fe7f8a297c67cfdbd148dddb5cbf9565198ae95fdf

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

module SystemMetrics
  class Engine < ::Rails::Engine

    attr_accessor :collector, :smc

    config.system_metrics = SystemMetrics::Config.new

    initializer "system_metrics.initialize", :before => "system_metrics.start_subscriber" do |app|
      self.smc = app.config.system_metrics
      raise ArgumentError.new(smc.errors) if smc.invalid?
      self.collector = SystemMetrics::Collector.new(smc.store)
    end

    initializer "system_metrics.start_subscriber", :before => "system_metrics.add_middleware" do |app|
      ActiveSupport::Notifications.subscribe /^[^!]/ do |*args|
        unless smc.notification_exclude_patterns.any? { |pattern| pattern =~ name }
          process_event SystemMetrics::NestedEvent.new(*args)
        end
      end
    end

    initializer "system_metrics.add_middleware", :before => :load_environment_config do |app|
      app.config.middleware.use SystemMetrics::Middleware, collector, smc.path_exclude_patterns
    end

    private

      def process_event(event)
        instrument = smc.instruments.find { |instrument| instrument.handles?(event) }

        if instrument.present?
          unless instrument.ignore?(event)
            instrument.prepare(event)
            collector.collect_event(event)
          end
        else
          collector.collect_event(event)
        end
      end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
system-metrics-0.2.5 lib/system_metrics/engine.rb
system-metrics-0.2.4 lib/system_metrics/engine.rb
system-metrics-0.2.3 lib/system_metrics/engine.rb
system-metrics-0.2.2 lib/system_metrics/engine.rb
system-metrics-0.2.1 lib/system_metrics/engine.rb
system-metrics-0.2.0 lib/system_metrics/engine.rb