lib/hawkular/metrics/metric_api.rb in hawkular-client-2.1.0 vs lib/hawkular/metrics/metric_api.rb in hawkular-client-2.2.0
- old
+ new
@@ -122,15 +122,25 @@
# @see #push_data #push_data for datapoint detail
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, buckets: nil, percentiles: nil, limit: nil,
order: nil)
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
percentiles: percentiles, limit: limit, order: order }
- resp = @client.http_get("/#{@resource}/#{ERB::Util.url_encode(id)}/data/?" +
- encode_params(params))
- resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
+ get_data_helper(id, params)
end
+ # Retrieve raw data for multiple metrics.
+ # @param ids [Array[String]] metric definition ids
+ # @param starts [Integer] optional timestamp (default now - 8h)
+ # @param ends [Integer] optional timestamp (default now)
+ # @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]] named datapoints
+ def raw_data(ids, starts: nil, ends: nil, limit: nil, order: nil)
+ params = { ids: ids, start: starts, end: ends, limit: limit, order: order }
+ @client.http_post("/#{@resource}/raw/query", params)
+ end
+
# Retrieve metric datapoints by tags
# @param tags [Hash]
# @param starts [Integer] optional timestamp (default now - 8h)
# @param ends [Integer] optional timestamp (default now)
# @param bucketDuration [String] optional interval (default no aggregation)
@@ -148,10 +158,18 @@
end
def encode_params(params)
URI.encode_www_form(params.select { |_k, v| !v.nil? })
end
+
+ private
+
+ def get_data_helper(id, params)
+ resp = @client.http_get("/#{@resource}/#{ERB::Util.url_encode(id)}/data/?" +
+ encode_params(params))
+ resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
+ end
end
# Class that interacts with "gauge" metric types
class Gauges < Metrics
# @param client [Client]
@@ -201,9 +219,27 @@
# Class that interacts with "availability" metric types
class Availability < Metrics
# @param client [Client]
def initialize(client)
super(client, 'availability', 'availability')
+ 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 buckets [Integer] optional desired number of buckets over the specified timerange
+ # @param bucketDuration [String] optional interval (default no aggregation)
+ # @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, bucketDuration: nil, buckets: nil, distinct: nil, limit: nil,
+ order: nil)
+ params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
+ distinct: distinct, limit: limit, order: order }
+ get_data_helper(id, params)
end
end
end
end