Start local prometheus_exporter server only in puma/sidekiq startup (#35005)
This commit is contained in:
parent
722fb1ff55
commit
1623d54ec0
4 changed files with 33 additions and 7 deletions
|
@ -5,16 +5,12 @@ if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
|
||||||
require 'prometheus_exporter/middleware'
|
require 'prometheus_exporter/middleware'
|
||||||
|
|
||||||
if ENV['MASTODON_PROMETHEUS_EXPORTER_LOCAL'] == 'true'
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_LOCAL'] == 'true'
|
||||||
require 'prometheus_exporter/server'
|
require 'mastodon/prometheus_exporter/local_server'
|
||||||
require 'prometheus_exporter/client'
|
|
||||||
|
|
||||||
# bind is the address, on which the webserver will listen
|
# bind is the address, on which the webserver will listen
|
||||||
# port is the port that will provide the /metrics route
|
# port is the port that will provide the /metrics route
|
||||||
server = PrometheusExporter::Server::WebServer.new bind: ENV.fetch('MASTODON_PROMETHEUS_EXPORTER_HOST', 'localhost'), port: ENV.fetch('MASTODON_PROMETHEUS_EXPORTER_PORT', '9394').to_i
|
Mastodon::PrometheusExporter::LocalServer.bind = ENV.fetch('MASTODON_PROMETHEUS_EXPORTER_HOST', 'localhost')
|
||||||
server.start
|
Mastodon::PrometheusExporter::LocalServer.port = ENV.fetch('MASTODON_PROMETHEUS_EXPORTER_PORT', '9394').to_i
|
||||||
|
|
||||||
# wire up a default local client
|
|
||||||
PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV['MASTODON_PROMETHEUS_EXPORTER_WEB_DETAILED_METRICS'] == 'true'
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_WEB_DETAILED_METRICS'] == 'true'
|
||||||
|
|
|
@ -26,6 +26,12 @@ Sidekiq.configure_server do |config|
|
||||||
require 'prometheus_exporter'
|
require 'prometheus_exporter'
|
||||||
require 'prometheus_exporter/instrumentation'
|
require 'prometheus_exporter/instrumentation'
|
||||||
|
|
||||||
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_LOCAL'] == 'true'
|
||||||
|
config.on :startup do
|
||||||
|
Mastodon::PrometheusExporter::LocalServer.setup!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
config.on :startup do
|
config.on :startup do
|
||||||
# Ruby process metrics (memory, GC, etc)
|
# Ruby process metrics (memory, GC, etc)
|
||||||
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
|
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
|
||||||
|
|
|
@ -21,6 +21,12 @@ if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
|
||||||
require 'prometheus_exporter'
|
require 'prometheus_exporter'
|
||||||
require 'prometheus_exporter/instrumentation'
|
require 'prometheus_exporter/instrumentation'
|
||||||
|
|
||||||
|
if ENV['MASTODON_PROMETHEUS_EXPORTER_LOCAL'] == 'true'
|
||||||
|
before_fork do
|
||||||
|
Mastodon::PrometheusExporter::LocalServer.setup!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
on_worker_boot do
|
on_worker_boot do
|
||||||
# Ruby process metrics (memory, GC, etc)
|
# Ruby process metrics (memory, GC, etc)
|
||||||
PrometheusExporter::Instrumentation::Process.start(type: 'puma')
|
PrometheusExporter::Instrumentation::Process.start(type: 'puma')
|
||||||
|
|
18
lib/mastodon/prometheus_exporter/local_server.rb
Normal file
18
lib/mastodon/prometheus_exporter/local_server.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'prometheus_exporter/server'
|
||||||
|
require 'prometheus_exporter/client'
|
||||||
|
|
||||||
|
module Mastodon::PrometheusExporter
|
||||||
|
module LocalServer
|
||||||
|
mattr_accessor :bind, :port
|
||||||
|
|
||||||
|
def self.setup!
|
||||||
|
server = PrometheusExporter::Server::WebServer.new(bind:, port:)
|
||||||
|
server.start
|
||||||
|
|
||||||
|
# wire up a default local client
|
||||||
|
PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue