Class: Hawkular::Metrics::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Metrics::Client
- Defined in:
- lib/hawkular/metrics/metric_api.rb,
lib/hawkular/metrics/tenant_api.rb,
lib/hawkular/metrics/metrics_client.rb
Overview
Client to access the Hawkular_metrics subsystem
Defined Under Namespace
Classes: Availability, Counters, Gauges, Metrics, Strings, Tenants
Instance Attribute Summary collapse
-
#avail ⇒ Availability
readonly
Access counters API.
-
#counters ⇒ Counters
readonly
Access counters API.
-
#gauges ⇒ Gauges
readonly
Access gauges API.
-
#legacy_api ⇒ boolean
readonly
If it's using the legacy API or not.
-
#strings ⇒ Strings
readonly
Access strings API.
-
#tenants ⇒ Tenants
readonly
Access tenants API.
Instance Method Summary collapse
- #check_version ⇒ Object
-
#data_by_tags(tags, buckets: nil, bucketDuration: nil, start: nil, ends: nil) ⇒ Array[Hash]
Retrieve all types of metrics datapoints by tags.
-
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Metrics.
-
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
constructor
Construct a new Hawkular Metrics client class.
-
#push_data(gauges: [], counters: [], availabilities: [], strings: []) ⇒ Object
Push data for multiple metrics of all supported types.
-
#query_stats(gauge_ids: [], counter_ids: [], avail_ids: [], rates: false, starts: nil, ends: nil, bucket_duration: '3600s') ⇒ Hash
Fetch stats for multiple metrics of all supported types.
-
#tags ⇒ Hash{String=>String}
Fetch all tags for metrics definitions.
- #tags_param(tags) ⇒ Object
Methods inherited from BaseClient
#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url_with_websocket_scheme
Methods included from ClientUtils
Constructor Details
#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client
Construct a new Hawkular Metrics client class. optional parameters
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 56 def initialize(entrypoint, credentials = {}, = {}) entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/metrics' super(entrypoint, credentials, ) check_version @tenants = Client::Tenants.new self @counters = Client::Counters.new self @gauges = Client::Gauges.new self @avail = Client::Availability.new self @strings = Client::Strings.new self end |
Instance Attribute Details
#avail ⇒ Availability (readonly)
Returns access counters API
31 32 33 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 31 def avail @avail end |
#counters ⇒ Counters (readonly)
Returns access counters API
25 26 27 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 25 def counters @counters end |
#gauges ⇒ Gauges (readonly)
Returns access gauges API
27 28 29 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 27 def gauges @gauges end |
#legacy_api ⇒ boolean (readonly)
Returns if it's using the legacy API or not
34 35 36 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 34 def legacy_api @legacy_api end |
#strings ⇒ Strings (readonly)
Returns access strings API
29 30 31 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 29 def strings @strings end |
#tenants ⇒ Tenants (readonly)
Returns access tenants API
23 24 25 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 23 def tenants @tenants end |
Instance Method Details
#check_version ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/hawkular/metrics/metrics_client.rb', line 36 def check_version version_status_hash = fetch_version_and_status fail_version_msg = 'Unable to determine implementation version for metrics' fail fail_version_msg if version_status_hash['Implementation-Version'].nil? version = version_status_hash['Implementation-Version'] major, minor = version.scan(/\d+/).map(&:to_i) fail fail_version_msg if major.nil? || minor.nil? @legacy_api = (major == 0 && minor < 16) end |
#data_by_tags(tags, buckets: nil, bucketDuration: nil, start: nil, ends: nil) ⇒ Array[Hash]
Retrieve all types of metrics datapoints by tags
26 27 28 29 30 31 32 |
# File 'lib/hawkular/metrics/metric_api.rb', line 26 def (, buckets: nil, bucketDuration:nil, start:nil, ends: nil) data = { tags: (), buckets: buckets, bucketDuration: bucketDuration, start: start, end: ends } http_post('metrics/stats/query', data) end |
#fetch_version_and_status ⇒ Hash{String=>String}
Return version and status information for the used version of Hawkular-Metrics
37 38 39 |
# File 'lib/hawkular/metrics/metric_api.rb', line 37 def fetch_version_and_status http_get('/status') end |
#push_data(gauges: [], counters: [], availabilities: [], strings: []) ⇒ Object
Push data for multiple metrics of all supported types
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hawkular/metrics/metric_api.rb', line 52 def push_data(gauges: [], counters: [], availabilities: [], strings: []) gauges.each { |g| g[:data] } counters.each { |g| g[:data] } availabilities.each { |g| g[:data] } strings.each { |g| g[:data] } data = { gauges: gauges, counters: counters, availabilities: availabilities, strings: strings } path = '/metrics/' @legacy_api ? path << 'data' : path << 'raw' http_post(path, data) end |
#query_stats(gauge_ids: [], counter_ids: [], avail_ids: [], rates: false, starts: nil, ends: nil, bucket_duration: '3600s') ⇒ Hash
Fetch stats for multiple metrics of all supported types
82 83 84 85 86 87 88 89 |
# File 'lib/hawkular/metrics/metric_api.rb', line 82 def query_stats(gauge_ids: [], counter_ids: [], avail_ids: [], rates: false, starts: nil, ends: nil, bucket_duration: '3600s') path = '/metrics/stats/query' metrics = { gauge: gauge_ids, counter: counter_ids, availability: avail_ids } 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 |
#tags ⇒ Hash{String=>String}
Fetch all tags for metrics definitions
93 94 95 96 97 98 99 100 101 |
# File 'lib/hawkular/metrics/metric_api.rb', line 93 def = [] http_get('/metrics/').map do |g| g['tags'].map do |k, v| << { k => v } end unless g['tags'].nil? end .uniq! end |
#tags_param(tags) ⇒ Object
15 16 17 |
# File 'lib/hawkular/metrics/metric_api.rb', line 15 def () .map { |k, v| "#{k}:#{v}" }.join(',') end |