2017-05-23 09:42:36 -04:00
|
|
|
require 'prometheus/client/formats/text'
|
|
|
|
|
|
|
|
class MetricsService
|
|
|
|
CHECKS = [
|
|
|
|
Gitlab::HealthChecks::DbCheck,
|
|
|
|
Gitlab::HealthChecks::RedisCheck,
|
|
|
|
Gitlab::HealthChecks::FsShardsCheck
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
def prometheus_metrics_text
|
|
|
|
Prometheus::Client::Formats::Text.marshal_multiprocess(multiprocess_metrics_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def health_metrics_text
|
2017-05-29 08:19:43 -04:00
|
|
|
metrics = CHECKS.flat_map(&:metrics)
|
2017-05-23 09:42:36 -04:00
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
formatter.marshal(metrics)
|
|
|
|
end
|
2017-05-23 09:42:36 -04:00
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
def metrics_text
|
2017-06-02 09:55:44 -04:00
|
|
|
"#{health_metrics_text}#{prometheus_metrics_text}"
|
2017-05-23 09:42:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-05-29 08:19:43 -04:00
|
|
|
def formatter
|
2017-05-29 17:23:19 -04:00
|
|
|
@formatter ||= Gitlab::HealthChecks::PrometheusTextFormat.new
|
2017-05-29 08:19:43 -04:00
|
|
|
end
|
|
|
|
|
2017-05-23 09:42:36 -04:00
|
|
|
def multiprocess_metrics_path
|
2017-05-29 17:23:19 -04:00
|
|
|
@multiprocess_metrics_path ||= Rails.root.join(ENV['prometheus_multiproc_dir']).freeze
|
2017-05-23 09:42:36 -04:00
|
|
|
end
|
|
|
|
end
|