diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 03:14:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 03:14:42 +0000 |
commit | c657078ecb4bff69e58f6911713e143c99f2c71f (patch) | |
tree | 5a4dc8bf80b14c3202de9c7bd51363f3d73af541 /metrics_server | |
parent | 498ba9dc41fcf2b4be30a8f3721543953efb3c3b (diff) | |
download | gitlab-ce-c657078ecb4bff69e58f6911713e143c99f2c71f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'metrics_server')
-rw-r--r-- | metrics_server/dependencies.rb | 25 | ||||
-rw-r--r-- | metrics_server/metrics_server.rb | 41 | ||||
-rw-r--r-- | metrics_server/settings_overrides.rb | 14 |
3 files changed, 80 insertions, 0 deletions
diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb new file mode 100644 index 00000000000..ecfef502feb --- /dev/null +++ b/metrics_server/dependencies.rb @@ -0,0 +1,25 @@ +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +require 'shellwords' +require 'fileutils' + +require 'active_support/concern' +require 'active_support/inflector' + +require 'prometheus/client' +require 'rack' + +require_relative 'settings_overrides' + +require_relative '../lib/gitlab/daemon' +require_relative '../lib/gitlab/utils/strong_memoize' +require_relative '../lib/prometheus/cleanup_multiproc_dir_service' +require_relative '../lib/gitlab/metrics/prometheus' +require_relative '../lib/gitlab/metrics' +require_relative '../lib/gitlab/metrics/exporter/base_exporter' +require_relative '../lib/gitlab/metrics/exporter/sidekiq_exporter' +require_relative '../lib/gitlab/health_checks/probes/collection' +require_relative '../lib/gitlab/health_checks/probes/status' + +# rubocop:enable Naming/FileName diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb new file mode 100644 index 00000000000..09171d8220b --- /dev/null +++ b/metrics_server/metrics_server.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require_relative '../config/bundler_setup' + +require_relative 'dependencies' + +class MetricsServer # rubocop:disable Gitlab/NamespacedClass + class << self + def spawn(target, gitlab_config: nil) + cmd = "#{Rails.root}/bin/metrics-server" + env = { + 'METRICS_SERVER_TARGET' => target, + 'GITLAB_CONFIG' => gitlab_config + } + + Process.spawn(env, cmd, err: $stderr, out: $stdout).tap do |pid| + Process.detach(pid) + end + end + end + + def initialize(target, metrics_dir) + @target = target + @metrics_dir = metrics_dir + end + + def start + ::Prometheus::Client.configure do |config| + config.multiprocess_files_dir = @metrics_dir + end + + FileUtils.mkdir_p(@metrics_dir, mode: 0700) + ::Prometheus::CleanupMultiprocDirService.new.execute + + settings = Settings.monitoring.sidekiq_exporter + exporter_class = "Gitlab::Metrics::Exporter::#{@target.camelize}Exporter".constantize + server = exporter_class.instance(settings, synchronous: true) + + server.start + end +end diff --git a/metrics_server/settings_overrides.rb b/metrics_server/settings_overrides.rb new file mode 100644 index 00000000000..4239f62ad1c --- /dev/null +++ b/metrics_server/settings_overrides.rb @@ -0,0 +1,14 @@ +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +# Sidekiq-cluster code is loaded both inside a Rails/Rspec +# context as well as outside of it via CLI invocation. When it +# is loaded outside of a Rails/Rspec context we do not have access +# to all necessary constants. For example, we need Rails.root to +# determine the location of bin/metrics-server. +# Here we make the necessary constants available conditionally. +require_relative '../scripts/override_rails_constants' unless Object.const_defined?('Rails') + +require_relative '../config/settings' + +# rubocop:enable Naming/FileName |