2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'webrick'
|
|
|
|
require 'prometheus/client/rack/exporter'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
module Exporter
|
|
|
|
class WebExporter < BaseExporter
|
|
|
|
ExporterCheck = Struct.new(:exporter) do
|
|
|
|
def readiness
|
|
|
|
Gitlab::HealthChecks::Result.new(
|
|
|
|
'web_exporter', exporter.running)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :running
|
|
|
|
|
|
|
|
# This exporter is always run on master process
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
# DEPRECATED:
|
|
|
|
# these `readiness_checks` are deprecated
|
|
|
|
# as presenting no value in a way how we run
|
|
|
|
# application: https://gitlab.com/gitlab-org/gitlab/issues/35343
|
2019-12-21 20:55:43 +05:30
|
|
|
self.readiness_checks = [
|
|
|
|
WebExporter::ExporterCheck.new(self),
|
|
|
|
Gitlab::HealthChecks::PumaCheck,
|
|
|
|
Gitlab::HealthChecks::UnicornCheck
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def settings
|
|
|
|
Gitlab.config.monitoring.web_exporter
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_filename
|
|
|
|
File.join(Rails.root, 'log', 'web_exporter.log')
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def mark_as_not_running!
|
|
|
|
@running = false
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def start_working
|
|
|
|
@running = true
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_working
|
2019-12-26 22:10:19 +05:30
|
|
|
mark_as_not_running!
|
2019-12-21 20:55:43 +05:30
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|