summaryrefslogtreecommitdiff
path: root/lib/gitlab/prometheus_client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/prometheus_client.rb')
-rw-r--r--lib/gitlab/prometheus_client.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/prometheus_client.rb b/lib/gitlab/prometheus_client.rb
index b03d8a4d254..213e3ba835d 100644
--- a/lib/gitlab/prometheus_client.rb
+++ b/lib/gitlab/prometheus_client.rb
@@ -71,6 +71,19 @@ module Gitlab
end
end
+ # Queries Prometheus with the given aggregate query and groups the results by mapping
+ # metric labels to their respective values.
+ #
+ # @return [Hash] mapping labels to their aggregate numeric values, or the empty hash if no results were found
+ def aggregate(aggregate_query, time: Time.now)
+ response = query(aggregate_query, time: time)
+ response.to_h do |result|
+ key = block_given? ? yield(result['metric']) : result['metric']
+ _timestamp, value = result['value']
+ [key, value.to_i]
+ end
+ end
+
def label_values(name = '__name__')
json_api_get("label/#{name}/values")
end