Add prometheus_exporter gem and instrumentation to the project

This commit is contained in:
Eugene Burmakin 2024-11-20 12:02:31 +01:00
parent 8b3602523f
commit 055faac14f
5 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby File.read('.ruby-version').strip ruby File.read('.ruby-version').strip
gem 'bootsnap', require: false gem 'bootsnap', require: false
gem 'prometheus_exporter'
gem 'chartkick' gem 'chartkick'
gem 'data_migrate' gem 'data_migrate'
gem 'devise' gem 'devise'

View file

@ -233,6 +233,8 @@ GEM
patience_diff (1.2.0) patience_diff (1.2.0)
optimist (~> 3.0) optimist (~> 3.0)
pg (1.5.9) pg (1.5.9)
prometheus_exporter (2.1.1)
webrick
pry (0.14.2) pry (0.14.2)
coderay (~> 1.1) coderay (~> 1.1)
method_source (~> 1.0) method_source (~> 1.0)
@ -408,6 +410,7 @@ GEM
addressable (>= 2.8.0) addressable (>= 2.8.0)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0) hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.9.0)
websocket-driver (0.7.6) websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
@ -441,6 +444,7 @@ DEPENDENCIES
lograge lograge
oj oj
pg pg
prometheus_exporter
pry-byebug pry-byebug
pry-rails pry-rails
puma puma

View file

@ -0,0 +1,15 @@
# in config/initializers/prometheus.rb
if Rails.env != "test"
require 'prometheus_exporter/middleware'
# This reports stats per request like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
if Rails.env != "test"
require 'prometheus_exporter/instrumentation'
# this reports basic process stats like RSS and GC info, type master
# means it is instrumenting the master process
PrometheusExporter::Instrumentation::Process.start(type: "master")
end

View file

@ -2,6 +2,11 @@
Sidekiq.configure_server do |config| Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] } config.redis = { url: ENV['REDIS_URL'] }
config.server_middleware do |chain|
require 'prometheus_exporter/instrumentation'
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
end end
Sidekiq.configure_client do |config| Sidekiq.configure_client do |config|

View file

@ -41,3 +41,9 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Allow puma to be restarted by `bin/rails restart` command. # Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart plugin :tmp_restart
# in unicorn/puma/passenger be sure to run a new process instrumenter after fork
after_worker_boot do
require 'prometheus_exporter/instrumentation'
PrometheusExporter::Instrumentation::Process.start(type:"web")
end