2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-06 10:07:33 -04:00
|
|
|
module Gitlab
|
|
|
|
module Prometheus
|
|
|
|
module Queries
|
|
|
|
class EnvironmentQuery < BaseQuery
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-06-06 10:07:33 -04:00
|
|
|
def query(environment_id)
|
2017-08-07 09:54:30 -04:00
|
|
|
::Environment.find_by(id: environment_id).try do |environment|
|
2017-06-20 09:53:55 -04:00
|
|
|
environment_slug = environment.slug
|
|
|
|
timeframe_start = 8.hours.ago.to_f
|
|
|
|
timeframe_end = Time.now.to_f
|
2017-04-26 16:09:03 -04:00
|
|
|
|
2017-06-20 09:53:55 -04:00
|
|
|
memory_query = raw_memory_usage_query(environment_slug)
|
|
|
|
cpu_query = raw_cpu_usage_query(environment_slug)
|
2017-04-26 16:09:03 -04:00
|
|
|
|
2017-06-20 09:53:55 -04:00
|
|
|
{
|
|
|
|
memory_values: client_query_range(memory_query, start: timeframe_start, stop: timeframe_end),
|
|
|
|
memory_current: client_query(memory_query, time: timeframe_end),
|
|
|
|
cpu_values: client_query_range(cpu_query, start: timeframe_start, stop: timeframe_end),
|
|
|
|
cpu_current: client_query(cpu_query, time: timeframe_end)
|
|
|
|
}
|
|
|
|
end
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-02-23 15:33:33 -05:00
|
|
|
|
|
|
|
def self.transform_reactive_result(result)
|
|
|
|
result[:metrics] = result.delete :data
|
|
|
|
result
|
|
|
|
end
|
2017-06-06 10:07:33 -04:00
|
|
|
end
|
2017-04-26 16:09:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|