Class: Wavefront::Query
Overview
Query Wavefront metrics.
Instance Attribute Summary
Attributes inherited from CoreApi
#api, #creds, #logger, #opts, #update_keys
Instance Method Summary collapse
- #api_base ⇒ Object
-
#query(query, granularity = nil, t_start = nil, t_end = nil, options = {}) ⇒ Wavefront::Response
GET /api/v2/chart/api Perform a charting query against Wavefront servers that returns the appropriate points in the specified time window and granularity.
-
#raw(metric, source = nil, t_start = nil, t_end = nil) ⇒ Object
GET /api/v2/chart/raw Perform a raw data query against Wavefront servers that returns second granularity points grouped by tags.
-
#response_shim(body, status) ⇒ Object
Fake a response which looks like we get from all the other paths.
Methods inherited from CoreApi
#api_path, #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
#wf_alert_id?, #wf_alert_severity?, #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_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_ts?, #wf_user_id?, #wf_value?, #wf_version?, #wf_webhook_id?
Constructor Details
This class inherits a constructor from Wavefront::CoreApi
Instance Method Details
#api_base ⇒ Object
8 9 10 |
# File 'lib/wavefront-sdk/query.rb', line 8 def api_base 'chart' end |
#query(query, granularity = nil, t_start = nil, t_end = nil, options = {}) ⇒ Wavefront::Response
GET /api/v2/chart/api Perform a charting query against Wavefront servers that returns the appropriate points in the specified time window and granularity. Any options can be pased through in the options hash. This means the SDK does not have to closely track the API, but also means the burden of data validation is down to the user.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wavefront-sdk/query.rb', line 31 def query(query, granularity = nil, t_start = nil, t_end = nil, = {}) raise ArgumentError unless query.is_a?(String) wf_granularity?(granularity) raise Wavefront::Exception::InvalidTimestamp if t_start.nil? [:q] = query [:g] = granularity [:s] = parse_time(t_start, true) [:e] = parse_time(t_end, true) if t_end .delete_if { |k, v| v == false && k != :i } api.get('api', ) end |
#raw(metric, source = nil, t_start = nil, t_end = nil) ⇒ Object
GET /api/v2/chart/raw Perform a raw data query against Wavefront servers that returns second granularity points grouped by tags
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wavefront-sdk/query.rb', line 60 def raw(metric, source = nil, t_start = nil, t_end = nil) raise ArgumentError unless metric.is_a?(String) = { metric: metric } if source wf_source_id?(source) [:source] = source end [:startTime] = parse_time(t_start, true) if t_start [:endTime] = parse_time(t_end, true) if t_end api.get('raw', ) end |
#response_shim(body, status) ⇒ Object
Fake a response which looks like we get from all the other paths. The default response is a single array.
79 80 81 82 83 84 |
# File 'lib/wavefront-sdk/query.rb', line 79 def response_shim(body, status) { response: JSON.parse(body), status: { result: status == 200 ? 'OK' : 'ERROR', message: '', code: status } }.to_json end |