debian-mirror-gitlab/lib/gitlab/metrics/sidekiq_metrics_exporter.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
require 'webrick'
require 'prometheus/client/rack/exporter'
module Gitlab
module Metrics
class SidekiqMetricsExporter < Daemon
2018-05-09 12:01:36 +05:30
LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log')
2017-09-10 17:25:29 +05:30
def enabled?
Gitlab::Metrics.metrics_folder_present? && settings.enabled
end
def settings
Settings.monitoring.sidekiq_exporter
end
private
attr_reader :server
def start_working
2018-05-09 12:01:36 +05:30
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-09-10 17:25:29 +05:30
server.mount "/", Rack::Handler::WEBrick, rack_app
server.start
end
def stop_working
2018-03-27 19:54:05 +05:30
server.shutdown if server
2017-09-10 17:25:29 +05:30
@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