2018-11-17 00:37:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-07 17:13:02 +00:00
|
|
|
require 'webrick'
|
|
|
|
require 'prometheus/client/rack/exporter'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
class SidekiqMetricsExporter < Daemon
|
2018-04-02 04:06:56 +00:00
|
|
|
LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log')
|
|
|
|
|
2017-08-07 17:13:02 +00:00
|
|
|
def enabled?
|
2019-02-14 18:05:35 +00:00
|
|
|
::Gitlab::Metrics.metrics_folder_present? && settings.enabled
|
2017-08-07 17:13:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def settings
|
|
|
|
Settings.monitoring.sidekiq_exporter
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :server
|
|
|
|
|
|
|
|
def start_working
|
2018-04-02 04:06:56 +00:00
|
|
|
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)
|
2017-08-07 17:13:02 +00:00
|
|
|
server.mount "/", Rack::Handler::WEBrick, rack_app
|
|
|
|
server.start
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_working
|
2018-02-21 05:46:25 +00:00
|
|
|
server.shutdown if server
|
2017-08-07 17:13:02 +00:00
|
|
|
@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
|