2017-05-23 09:42:36 -04:00
|
|
|
require 'prometheus/client/formats/text'
|
|
|
|
|
|
|
|
class MetricsService
|
|
|
|
CHECKS = [
|
|
|
|
Gitlab::HealthChecks::DbCheck,
|
2017-07-10 23:35:47 -04:00
|
|
|
Gitlab::HealthChecks::Redis::RedisCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::CacheCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::QueuesCheck,
|
|
|
|
Gitlab::HealthChecks::Redis::SharedStateCheck,
|
2017-05-23 09:42:36 -04:00
|
|
|
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-07-19 04:54:39 -04:00
|
|
|
::Prometheus::Client.configuration.multiprocess_files_dir
|
2017-05-23 09:42:36 -04:00
|
|
|
end
|
|
|
|
end
|