在Rails中捕获请求加载时间

时间:2018-07-31 19:21:11

标签: ruby-on-rails

我有一个简单的请求捕获方法,可以存储有关HTTP请求的所有信息,以帮助进行错误报告并捕获其他指标。我在ApplicationController的around_filter中有此记录,因此可以在任何需要的时候创建新记录。

class ApplicationController < ActionController::Base
  around_action :create_request

  def create_request
    Request.create!(
      host: request.host,
      domain: request.domain,
      format: request.format,
      method: request.method,
      port: request.port,
      protocol: request.protocol,
      query_string: request.query_string,
      remote_ip: request.remote_ip,
      url: request.url,
      controller_name: controller_path,
      action_name: action_name,
      response_code: response.code
    )
    yield
  end
end

enter image description here

如果您在运行Rails应用程序时曾经查看服务器日志,那么您会看到是否告诉您应用程序加载了多长时间。如何在每个页面请求中捕获该指标,我可以告诉我应用程序在不同的客户端,网络等上的运行情况?

我还没有找到任何能使我捕捉到请求时间或将请求加载到responserequest对象中的时间的指令。有任何想法吗?

0 个答案:

没有答案