lib/hawkular/metrics/metric_api.rb in hawkular-client-2.7.0 vs lib/hawkular/metrics/metric_api.rb in hawkular-client-2.8.0
- old
+ new
@@ -28,15 +28,16 @@
# client.push_data(counters: [{:id => "counter1", :data => [{:value => 1}, {:value => 2}]},
# {:id => "counter2", :data => [{:value => 1}, {:value => 3}]}])
# @example push gauge and availability datapoints
# client.push_data(gauges: [{:id => "gauge1", :data => [{:value => 1}, {:value => 2}]}],
# availabilities: [{:id => "avail1", :data => [{:value => "up"}]}])
- def push_data(gauges: [], counters: [], availabilities: [])
+ def push_data(gauges: [], counters: [], availabilities: [], strings: [])
gauges.each { |g| default_timestamp g[:data] }
counters.each { |g| default_timestamp g[:data] }
availabilities.each { |g| default_timestamp g[:data] }
- data = { gauges: gauges, counters: counters, availabilities: availabilities }
+ strings.each { |g| default_timestamp g[:data] }
+ data = { gauges: gauges, counters: counters, availabilities: availabilities, strings: strings }
path = '/metrics/'
@legacy_api ? path << 'data' : path << 'raw'
http_post(path, data)
end
@@ -66,10 +67,22 @@
data = { metrics: metrics, start: starts, end: ends, bucketDuration: bucket_duration }
data['types'] = %w(gauge gauge_rate counter counter_rate availability) if rates
http_post(path, data)
end
+ # Fetch all tags for metrics definitions
+ # @return [Hash{String=>String}]
+ def tags
+ tags = []
+ http_get('/metrics/').map do |g|
+ g['tags'].map do |k, v|
+ tags << { k => v }
+ end unless g['tags'].nil?
+ end
+ tags.uniq!
+ end
+
# Base class for accessing metric definition and data of all
# types (counters, gauges, availabilities).
class Metrics
# @param client [Client]
# @param metric_type [String] metric type (one of "counter", "gauge", "availability")
@@ -247,14 +260,36 @@
# @param bucket_duration [String] optional interval (default no
# aggregation)
# @return [Array[Hash]] rate points
def get_rate(id, starts: nil, ends: nil, bucket_duration: nil)
path = "/#{@resource}/#{ERB::Util.url_encode(id)}/rate"
- path << '/stats' unless bucket_duration.nil? && @legacy_api
+ path << '/stats' unless bucket_duration.nil? || @legacy_api
params = { start: starts, end: ends, bucketDuration: bucket_duration }
resp = @client.http_get(path + '?' + encode_params(params))
# API returns no content (empty Hash) instead of empty array
resp.is_a?(Array) ? resp : []
+ end
+ end
+
+ # Class that interacts with "string" metric types
+ class Strings < Metrics
+ # @param client [Client]
+ def initialize(client)
+ super(client, 'string', 'strings')
+ end
+
+ # Retrieve metric datapoints
+ # @param id [String] metric definition id
+ # @param starts [Integer] optional timestamp (default now - 8h)
+ # @param ends [Integer] optional timestamp (default now)
+ # @param distinct [String] optional set to true to return only distinct, contiguous values
+ # @param limit [Integer] optional limit the number of data points returned
+ # @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
+ # @return [Array[Hash]] datapoints
+ # @see #push_data #push_data for datapoint detail
+ def get_data(id, starts: nil, ends: nil, distinct: nil, limit: nil, order: nil)
+ params = { start: starts, end: ends, distinct: distinct, limit: limit, order: order }
+ get_data_helper(id, params)
end
end
# Class that interacts with "availability" metric types
class Availability < Metrics