Sha256: c28ed6dd6b9305b1edb2b0fd1f985354eff535457d8bbdfd54557e20540433e6

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

module Datadog::Notifications::Plugins
  class ActionController < Base

    attr_reader :metric_name

    # Options:
    #
    # *<tt>:metric_name</tt> - the metric name, defaults to "rails.request"
    # *<tt>:tags</tt> - additional tags
    def initialize(opts = {})
      super
      @metric_name = opts[:metric_name] || "rails.request"

      Datadog::Notifications.subscribe 'process_action.action_controller' do |reporter, event|
        record reporter, event
      end
    end

    private

    def record(reporter, event)
      payload = event.payload
      method  = payload[:method].downcase
      status  = payload[:status]
      action  = payload[:action]
      ctrl    = payload[:controller].sub(/Controller$/, '').underscore
      format  = payload[:format]
      tags    = self.tags + %W|method:#{method} status:#{status} action:#{action} controller:#{ctrl} format:#{format}|

      reporter.batch do
        reporter.increment metric_name, tags: tags
        reporter.timing "#{metric_name}.time", event.duration, tags: tags
        reporter.timing "#{metric_name}.time.db", payload[:db_runtime], tags: tags
        reporter.timing "#{metric_name}.time.view", payload[:view_runtime], tags: tags
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datadog-notifications-0.5.0 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.9 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.8 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.7 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.6 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.5 lib/datadog/notifications/plugins/action_controller.rb
datadog-notifications-0.4.4 lib/datadog/notifications/plugins/action_controller.rb