Class: Wavefront::Client
- Inherits:
-
Object
- Object
- Wavefront::Client
- Includes:
- Constants
- Defined in:
- lib/wavefront/client.rb,
lib/wavefront/client/version.rb
Constant Summary collapse
- DEFAULT_PATH =
'/chart/api'- VERSION =
"3.3.0"
Constants included from Constants
Wavefront::Constants::ALERT_FORMATS, Wavefront::Constants::DEFAULT_ALERT_FORMAT, Wavefront::Constants::DEFAULT_FORMAT, Wavefront::Constants::DEFAULT_HOST, Wavefront::Constants::DEFAULT_INFILE_FORMAT, Wavefront::Constants::DEFAULT_OBSOLETE_METRICS, Wavefront::Constants::DEFAULT_PERIOD_SECONDS, Wavefront::Constants::DEFAULT_PREFIX_LENGTH, Wavefront::Constants::DEFAULT_PROXY, Wavefront::Constants::DEFAULT_PROXY_PORT, Wavefront::Constants::DEFAULT_STRICT, Wavefront::Constants::EVENT_LEVELS, Wavefront::Constants::EVENT_STATE_DIR, Wavefront::Constants::FORMATS, Wavefront::Constants::GRANULARITIES
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Client
constructor
A new instance of Client.
- #query(query, granularity = 'm', options = {}) ⇒ Object
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false) ⇒ Client
33 34 35 36 37 |
# File 'lib/wavefront/client.rb', line 33 def initialize(token, host=DEFAULT_HOST, debug=false) @headers = {'X-AUTH-TOKEN' => token} @base_uri = URI::HTTPS.build(:host => host, :path => DEFAULT_PATH) debug(debug) end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
31 32 33 |
# File 'lib/wavefront/client.rb', line 31 def base_uri @base_uri end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
31 32 33 |
# File 'lib/wavefront/client.rb', line 31 def headers @headers end |
Instance Method Details
#query(query, granularity = 'm', options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wavefront/client.rb', line 39 def query(query, granularity='m', ={}) [:end_time] ||= Time.now.utc [:start_time] ||= [:end_time] - DEFAULT_PERIOD_SECONDS [:response_format] ||= DEFAULT_FORMAT [:prefix_length] ||= DEFAULT_PREFIX_LENGTH [:strict] = DEFAULT_STRICT unless .keys.include?(:strict) [:includeObsoleteMetrics] = DEFAULT_OBSOLETE_METRICS unless .keys.include?(:includeObsoleteMetrics) [ [:start_time], [:end_time] ].each { |o| raise Wavefront::Exception::InvalidTimeFormat unless o.is_a?(Time) } raise Wavefront::Exception::InvalidGranularity unless GRANULARITIES.include?(granularity) raise Wavefront::Exception::InvalidResponseFormat unless FORMATS.include?([:response_format]) raise InvalidPrefixLength unless [:prefix_length].is_a?(Fixnum) args = {:params => {:q => query, :g => granularity, :n => 'Unknown', :s => [:start_time].to_i, :e => [:end_time].to_i, :strict => [:strict], :includeObsoleteMetrics => [:includeObsoleteMetrics] }}.merge(@headers) if [:passthru] args[:params].merge!([:passthru]) end response = RestClient.get @base_uri.to_s, args klass = Object.const_get('Wavefront').const_get('Response').const_get([:response_format].to_s.capitalize) return klass.new(response, ) end |