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.6.2"
Constants included from Constants
Wavefront::Constants::ALERT_FORMATS, Wavefront::Constants::DASH_FORMATS, Wavefront::Constants::DEFAULT_ALERT_FORMAT, Wavefront::Constants::DEFAULT_DASH_FORMAT, Wavefront::Constants::DEFAULT_FORMAT, Wavefront::Constants::DEFAULT_HOST, Wavefront::Constants::DEFAULT_INFILE_FORMAT, Wavefront::Constants::DEFAULT_OBSOLETE_METRICS, Wavefront::Constants::DEFAULT_OPTS, Wavefront::Constants::DEFAULT_PERIOD_SECONDS, Wavefront::Constants::DEFAULT_PREFIX_LENGTH, Wavefront::Constants::DEFAULT_PROXY, Wavefront::Constants::DEFAULT_PROXY_PORT, Wavefront::Constants::DEFAULT_SOURCE_FORMAT, Wavefront::Constants::DEFAULT_STRICT, Wavefront::Constants::EVENT_LEVELS, Wavefront::Constants::EVENT_STATE_DIR, Wavefront::Constants::FORMATS, Wavefront::Constants::GRANULARITIES, Wavefront::Constants::SOURCE_FORMATS
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#noop ⇒ Object
readonly
Returns the value of attribute noop.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Client
constructor
A new instance of Client.
- #query(query, granularity = 'm', options = {}) ⇒ Object
Constructor Details
#initialize(token, host = DEFAULT_HOST, debug = false, options = {}) ⇒ Client
Returns a new instance of Client.
33 34 35 36 37 38 39 |
# File 'lib/wavefront/client.rb', line 33 def initialize(token, host=DEFAULT_HOST, debug=false, = {}) @verbose = [:verbose] @noop = [:noop] @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 |
#noop ⇒ Object (readonly)
Returns the value of attribute noop.
31 32 33 |
# File 'lib/wavefront/client.rb', line 31 def noop @noop end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
31 32 33 |
# File 'lib/wavefront/client.rb', line 31 def verbose @verbose end |
Instance Method Details
#query(query, granularity = 'm', options = {}) ⇒ Object
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 71 72 73 74 |
# File 'lib/wavefront/client.rb', line 41 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?(Integer) 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 puts "GET #{@base_uri.to_s}\nPARAMS #{args.to_s}" if (verbose || noop) return if noop 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 |