在视图中显示 Rails 响应时间

发布于 2024-08-16 03:35:39 字数 1177 浏览 2 评论 0原文

我正在尝试为我的 Rails 应用程序设置自定义 Pingdom 监控,并希望制作一个如下所示的 XML 响应:

<?xml version="1.0" encoding="UTF-8"?>
<pingdom_http_custom_check>
  <status>OK</status>
  <response_time>210.22</response_time>
</pingdom_http_custom_check>

其中,response_time 值是 Rails 呈现 XML 响应所花费的时间。

我发现了一些 资源用于使用 Mongrel 执行此操作,但我使用的是 Apache Passenger。

我有一个作为 Sinatra-Metal 端点实现的解决方案,如下所示:

class Pingdom < Sinatra::Base  
  set :views, "#{RAILS_ROOT}/app/views/metal"
  get '/pingdom' do
    @start_time = Time.now
    builder :pingdom
  end
end

然后我有一个构建器视图:(

xml.instruct!
xml.pingdom_http_custom_check do |pingdom_http_custom_check|
  pingdom_http_custom_check.status("OK")
  pingdom_http_custom_check.response_time((Time.now-@start_time)*1000)
end

请注意,response_time 以毫秒为单位)。

此实现足以检查应用程序是否已启动,但事实上它是一个金属端点,这意味着它实际上并未访问主 Rails 应用程序,因此实际上并不是衡量应用程序当前响应时间的一个很好的方法。

有人对更好的方法有什么好的建议吗?

干杯,阿尔丰

I'm trying to set up custom Pingdom monitoring of my Rails application and would like to craft an XML response that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<pingdom_http_custom_check>
  <status>OK</status>
  <response_time>210.22</response_time>
</pingdom_http_custom_check>

Where the response_time value is the time taken for Rails to render the XML response.

I've found some resources for doing this with Mongrel but I'm using Apache Passenger.

I have a solution implemented as a Sinatra-Metal endpoint like this:

class Pingdom < Sinatra::Base  
  set :views, "#{RAILS_ROOT}/app/views/metal"
  get '/pingdom' do
    @start_time = Time.now
    builder :pingdom
  end
end

and then I have a builder view:

xml.instruct!
xml.pingdom_http_custom_check do |pingdom_http_custom_check|
  pingdom_http_custom_check.status("OK")
  pingdom_http_custom_check.response_time((Time.now-@start_time)*1000)
end

(Note the response_time is in milliseconds).

This implementation is sufficient for checking that the application is up but the very fact that it is a metal endpoint means that it's not actually hitting the main Rails application and so isn't really a very good measure of the current response time of my application.

Does anyone have any good suggestions for a better approach?

Cheers, Arfon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽清风入怀 2024-08-23 03:35:39

响应时间说明什么?您是否考虑过使用侦察兵或新遗物之类的东西来代替?

What does the response time indicate? Have you considered using something like scout or new relic instead?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文