2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
class MetricsController < ActionController::Base
|
2017-07-03 11:09:34 -04:00
|
|
|
include RequiresWhitelistedMonitoringClient
|
2017-05-23 10:23:43 -04:00
|
|
|
|
2018-06-21 06:44:31 -04:00
|
|
|
protect_from_forgery with: :exception, prepend: true
|
2017-05-23 10:23:43 -04:00
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
def index
|
2017-09-25 17:38:34 -04:00
|
|
|
response = if Gitlab::Metrics.prometheus_metrics_enabled?
|
2021-09-21 14:11:18 -04:00
|
|
|
Gitlab::Metrics::RailsSlis.initialize_request_slis_if_needed!
|
2017-09-25 17:38:34 -04:00
|
|
|
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
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2018-11-28 13:08:21 -05:00
|
|
|
render plain: response, content_type: 'text/plain; version=0.0.4'
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|
|
|
|
|
2021-01-13 07:10:27 -05:00
|
|
|
def system
|
|
|
|
render json: system_metrics
|
|
|
|
end
|
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
private
|
|
|
|
|
2017-05-23 09:42:36 -04:00
|
|
|
def metrics_service
|
|
|
|
@metrics_service ||= MetricsService.new
|
2017-05-19 12:27:36 -04:00
|
|
|
end
|
2021-01-13 07:10:27 -05:00
|
|
|
|
|
|
|
def system_metrics
|
|
|
|
Gitlab::Metrics::System.summary.merge(
|
2021-06-18 11:10:16 -04:00
|
|
|
worker_id: ::Prometheus::PidProvider.worker_id
|
2021-01-13 07:10:27 -05:00
|
|
|
)
|
|
|
|
end
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|