[prometheus,rails]如何在rails服务器上启用prometheus

Posted

技术标签:

【中文标题】[prometheus,rails]如何在rails服务器上启用prometheus【英文标题】:[promethues, rails]How to enable promethues on rails server 【发布时间】:2015-11-24 23:52:42 【问题描述】:

我有一个 live rails 应用程序,我正在尝试使用它的 Ruby Client 安装 prometheus monitoring service。

我在服务器上运行教程,它运行良好,但一个小时后 merics url 死了。

如何让它在我的实时服务器上运行?

如果我添加一个现有项目,如下所示,Prometheus 会给出“未找到”错误

I, [2015-08-31T10:54:40.274066 #3542]  INFO -- : Refreshing Gem list
/PATH/shared/bundle/ruby/2.2.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- prometheus/client/rack/collector (LoadError)
    from /PATH/shared/bundle/ruby/2.2.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
    from /PATH/shared/bundle/ruby/2.2.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /PATH/shared/bundle/ruby/2.2.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
    from config.ru:8:in `block in <main>'
    from /PATH/shared/bundle/ruby/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
    from /PATH/shared/bundle/ruby/2.2.0/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
    from config.ru:1:in `new'
    from config.ru:1:in `<main>'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn.rb:48:in `eval'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn.rb:48:in `block in builder'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:768:in `call'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:768:in `build_app!'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:632:in `init_worker_process'
    from PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:655:in `worker_loop'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:529:in `spawn_missing_workers'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:540:in `maintain_worker_count'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:294:in `join'
    from /PATH/shared/bundle/ruby/2.2.0/gems/unicorn-4.9.0/bin/unicorn:126:in `<top (required)>'
    from /PATH/shared/bundle/ruby/2.2.0/bin/unicorn:23:in `load'
    from /PATH/shared/bundle/ruby/2.2.0/bin/unicorn:23:in `<main>'

我有两台服务器

    promethus_server live_server + prometheus 客户端)

live_server 和 promethus_client 在不同的路径中。

我在服务器上手动运行 promethus 客户端:

$ rails new client
$ bundle (adding promethus-client Gem)
$ vi config.ru (add promethus lib)
$ rail s --binding=IP

这对吗?

【问题讨论】:

您是否将 gem 安装到该服务器? 这是我最近升级的应用程序的 config.ru 的样子: require ::File.expand_path('../config/environment', FILE) require ' rack' 需要 'prometheus/client/rack/collector' 需要 'prometheus/client/rack/exporter' 使用 Prometheus::Client::Rack::Collector 使用 Prometheus::Client::Rack::Exporter 运行 Rails.application跨度> @Dan 我添加 gem 并使用您的配置文件更改配置文件。 THX :) 不客气。我继续添加它作为答案。 【参考方案1】:

这是我最近升级的应用程序的config.ru 的样子:

require ::File.expand_path('../config/environment', FILE)
require 'rack'
require 'prometheus/client/rack/collector'
require 'prometheus/client/rack/exporter'

use Prometheus::Client::Rack::Collector
use Prometheus::Client::Rack::Exporter

run Rails.application

【讨论】:

以上是关于[prometheus,rails]如何在rails服务器上启用prometheus的主要内容,如果未能解决你的问题,请参考以下文章

如何在带有 Rails 4.2 的专用调试端口上使用工头启动 Rails?

如何在 Rails 6 中使用茧宝石

如何在 Webpacker 中使用 Rails Url 助手/Rails 5.1 中的 React-rails

如何在我的 Rails 控制台中查看 Rails 审计记录?

如何在 Rails 中引发异常,使其表现得像其他 Rails 异常?

如何使 animate.css 在 Rails 中工作?由于 animate-rails 不适用于 heroku