Class: Wavefront::Unstable::Chart
- Defined in:
- lib/wavefront-sdk/unstable/chart.rb
Overview
This is an unstable class. Please refer to README.md.
Instance Attribute Summary
Attributes inherited from CoreApi
#api, #creds, #logger, #opts, #update_keys
Instance Method Summary collapse
- #all_metrics ⇒ Object
-
#api_path ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize.
-
#metrics_under(path, cursor = nil, limit = 100) ⇒ Wavefront::Response
Gets a list of metrics under the given path.
-
#response_shim(resp, status) ⇒ Object
We have to try to make the response we get from the API look like the one we get from the public API.
Methods inherited from CoreApi
#api_base, #hash_for_update, #initialize, #setup_api, #time_to_ms
Methods included from Mixins
#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?
Methods included from Validators
#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?
Constructor Details
This class inherits a constructor from Wavefront::CoreApi
Instance Method Details
#all_metrics ⇒ Object
12 13 14 |
# File 'lib/wavefront-sdk/unstable/chart.rb', line 12 def all_metrics metrics_under('') end |
#api_path ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize
51 52 53 |
# File 'lib/wavefront-sdk/unstable/chart.rb', line 51 def api_path '/chart' end |
#metrics_under(path, cursor = nil, limit = 100) ⇒ Wavefront::Response
Gets a list of metrics under the given path. This must be done via recursive calls to the API, so calls can take a while. If you ask for all your metrics, expect to be waiting some time.
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wavefront-sdk/unstable/chart.rb', line 24 def metrics_under(path, cursor = nil, limit = 100) resp = api.get('metrics/all', { trie: true, q: path, p: cursor, l: limit }.compact) return resp unless resp.ok? metrics = resp.response.items metrics.each do |m| if m.end_with?('.') metrics += metrics_under(m).response.items metrics.delete(m) end end # resp.more_items? doesn't work: we don't get that from this API if metrics.size == limit metrics += metrics_under(path, metrics.last, limit).response.items end resp.response.items = metrics.sort resp end |
#response_shim(resp, status) ⇒ Object
We have to try to make the response we get from the API look like the one we get from the public API. To begin with, it’s nothing like it.
This method must be public because a #respond_to? looks for it.
62 63 64 65 66 67 |
# File 'lib/wavefront-sdk/unstable/chart.rb', line 62 def response_shim(resp, status) { response: parse_response(resp), status: { result: status == 200 ? 'OK' : 'ERROR', message: (status, resp), code: status } }.to_json end |