module NewrelicRouteCheck

Constants

VERSION

Public Class Methods

actions_from_new_relic(file) click to toggle source
# File lib/newrelic_route_check.rb, line 17
def self.actions_from_new_relic(file)
  new_relic_controller_actions = []
  CSV.foreach(file, :col_sep => ",") do |row|
    if row.first && !['HttpDispatcher','Action'].include?(row.first.chomp) && !row.first.chomp.include?('#(template only)')
      new_relic_controller_actions << row.first.chomp
    end
  end
  new_relic_controller_actions.uniq
end
actions_from_routes() click to toggle source
# File lib/newrelic_route_check.rb, line 7
def self.actions_from_routes
  controller_actions = application.routes.routes.inject({}) do |controller_actions, route|
    if route.requirements[:controller]
      (controller_actions[route.requirements[:controller]] ||= []) << route.requirements[:action]
    end
    controller_actions
  end
  controller_actions.keys.map{|controller| controller_actions[controller].map{|action| "#{controller.camelize}Controller##{action}"}}.flatten.uniq
end
routes_diff_output(new_relic_controller_actions, formatted_routes_actions) click to toggle source
# File lib/newrelic_route_check.rb, line 27
def self.routes_diff_output(new_relic_controller_actions, formatted_routes_actions)
  puts "found #{new_relic_controller_actions.length} uniq new relic controller action hits"
  puts "found #{formatted_routes_actions.length} uniq Rails routes controller action pairs"

  only_new_relic = new_relic_controller_actions - formatted_routes_actions
  puts "exists in new relic, but not in routes: #{only_new_relic.length}"
  puts only_new_relic

  not_hit_in_new_relic = formatted_routes_actions - new_relic_controller_actions
  puts "never accessed in new relic stats: #{not_hit_in_new_relic.length}"
  puts not_hit_in_new_relic
end

Private Class Methods

application() click to toggle source
# File lib/newrelic_route_check.rb, line 42
def self.application
  if Rails::VERSION::MAJOR.to_i >= 3
    Rails.application
  else
    Rails::Application
  end
end