summaryrefslogtreecommitdiff
path: root/app/controllers/metrics_controller.rb
blob: bfd6181a940da01fbda9bba5dcdd181919ca023c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

# rubocop:disable Rails/ApplicationController
class MetricsController < ActionController::Base
  include RequiresWhitelistedMonitoringClient

  protect_from_forgery with: :exception, prepend: true

  def index
    response = if Gitlab::Metrics.prometheus_metrics_enabled?
                 metrics_service.metrics_text
               else
                 help_page = help_page_url('administration/monitoring/prometheus/gitlab_metrics',
                                           anchor: 'gitlab-prometheus-metrics'
                                          )
                 "# Metrics are disabled, see: #{help_page}\n"
               end

    render plain: response, content_type: 'text/plain; version=0.0.4'
  end

  def system
    render json: system_metrics
  end

  private

  def metrics_service
    @metrics_service ||= MetricsService.new
  end

  def system_metrics
    Gitlab::Metrics::System.summary.merge(
      worker_id: ::Prometheus::PidProvider.worker_id
    )
  end
end
# rubocop:enable Rails/ApplicationController