debian-mirror-gitlab/lib/gitlab/prometheus/queries/environment_query.rb

35 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Gitlab
module Prometheus
module Queries
class EnvironmentQuery < BaseQuery
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
def query(environment_id)
::Environment.find_by(id: environment_id).try do |environment|
environment_slug = environment.slug
timeframe_start = 8.hours.ago.to_f
timeframe_end = Time.now.to_f
memory_query = raw_memory_usage_query(environment_slug)
cpu_query = raw_cpu_usage_query(environment_slug)
{
2020-04-22 19:07:51 +05:30
memory_values: client_query_range(memory_query, start_time: timeframe_start, end_time: timeframe_end),
2017-09-10 17:25:29 +05:30
memory_current: client_query(memory_query, time: timeframe_end),
2020-04-22 19:07:51 +05:30
cpu_values: client_query_range(cpu_query, start_time: timeframe_start, end_time: timeframe_end),
2017-09-10 17:25:29 +05:30
cpu_current: client_query(cpu_query, time: timeframe_end)
}
end
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-03-27 19:54:05 +05:30
def self.transform_reactive_result(result)
result[:metrics] = result.delete :data
result
end
2017-09-10 17:25:29 +05:30
end
end
end
end