05e1cbc4ca
The Sidekiq exporter logs were mixing with the normal Sidekiq logs. In order to support structured logging in Sidekiq, we either need to split this data out or convert the exporter to produce structured logs. Since Sidekiq job processing is fundamentally different information from Web server traffic, it seems cleaner to move the metrics traffic into a separate file, where they can be parsed by a different filter if needed. Relates to #20060
47 lines
1.1 KiB
Ruby
47 lines
1.1 KiB
Ruby
require 'webrick'
|
|
require 'prometheus/client/rack/exporter'
|
|
|
|
module Gitlab
|
|
module Metrics
|
|
class SidekiqMetricsExporter < Daemon
|
|
LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log')
|
|
|
|
def enabled?
|
|
Gitlab::Metrics.metrics_folder_present? && settings.enabled
|
|
end
|
|
|
|
def settings
|
|
Settings.monitoring.sidekiq_exporter
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :server
|
|
|
|
def start_working
|
|
logger = WEBrick::Log.new(LOG_FILENAME)
|
|
access_log = [
|
|
[logger, WEBrick::AccessLog::COMBINED_LOG_FORMAT]
|
|
]
|
|
|
|
@server = ::WEBrick::HTTPServer.new(Port: settings.port, BindAddress: settings.address,
|
|
Logger: logger, AccessLog: access_log)
|
|
server.mount "/", Rack::Handler::WEBrick, rack_app
|
|
server.start
|
|
end
|
|
|
|
def stop_working
|
|
server.shutdown if server
|
|
@server = nil
|
|
end
|
|
|
|
def rack_app
|
|
Rack::Builder.app do
|
|
use Rack::Deflater
|
|
use ::Prometheus::Client::Rack::Exporter
|
|
run -> (env) { [404, {}, ['']] }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|