2019-10-04 02:06:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'webrick'
|
|
|
|
require 'prometheus/client/rack/exporter'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
module Exporter
|
|
|
|
class WebExporter < BaseExporter
|
2019-10-16 11:06:17 -04:00
|
|
|
ExporterCheck = Struct.new(:exporter) do
|
|
|
|
def readiness
|
|
|
|
Gitlab::HealthChecks::Result.new(
|
|
|
|
'web_exporter', exporter.running)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :running
|
|
|
|
|
2019-10-16 08:06:32 -04:00
|
|
|
# This exporter is always run on master process
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2019-11-07 10:06:33 -05:00
|
|
|
# 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-10-16 14:08:01 -04:00
|
|
|
self.readiness_checks = [
|
2019-10-16 11:06:17 -04:00
|
|
|
WebExporter::ExporterCheck.new(self),
|
2019-10-16 08:06:32 -04:00
|
|
|
Gitlab::HealthChecks::PumaCheck,
|
|
|
|
Gitlab::HealthChecks::UnicornCheck
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-10-04 02:06:05 -04:00
|
|
|
def settings
|
2019-10-16 11:06:17 -04:00
|
|
|
Gitlab.config.monitoring.web_exporter
|
2019-10-04 02:06:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def log_filename
|
|
|
|
File.join(Rails.root, 'log', 'web_exporter.log')
|
|
|
|
end
|
2019-10-16 11:06:17 -04:00
|
|
|
|
2019-11-07 10:06:33 -05:00
|
|
|
def mark_as_not_running!
|
|
|
|
@running = false
|
|
|
|
end
|
|
|
|
|
2019-10-16 11:06:17 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def start_working
|
|
|
|
@running = true
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_working
|
2019-11-07 10:06:33 -05:00
|
|
|
mark_as_not_running!
|
2019-10-16 11:06:17 -04:00
|
|
|
super
|
|
|
|
end
|
2019-10-04 02:06:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|