class Wavefront::Client
Constants
- DEFAULT_PATH
- VERSION
Attributes
base_uri[R]
headers[R]
noop[R]
verbose[R]
Public Class Methods
new(token, host=DEFAULT_HOST, debug=false, options = {})
click to toggle source
# File lib/wavefront/client.rb, line 33 def initialize(token, host=DEFAULT_HOST, debug=false, options = {}) @verbose = options[:verbose] @noop = options[:noop] @headers = {'X-AUTH-TOKEN' => token} @base_uri = URI::HTTPS.build(:host => host, :path => DEFAULT_PATH) debug(debug) end
Public Instance Methods
query(query, granularity='m', options={})
click to toggle source
# File lib/wavefront/client.rb, line 41 def query(query, granularity='m', options={}) options[:end_time] ||= Time.now.utc options[:start_time] ||= options[:end_time] - DEFAULT_PERIOD_SECONDS options[:response_format] ||= DEFAULT_FORMAT options[:prefix_length] ||= DEFAULT_PREFIX_LENGTH options[:strict] = DEFAULT_STRICT unless options.keys.include?(:strict) options[:includeObsoleteMetrics] = DEFAULT_OBSOLETE_METRICS unless options.keys.include?(:includeObsoleteMetrics) [ options[:start_time], options[: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?(options[:response_format]) raise InvalidPrefixLength unless options[:prefix_length].is_a?(Integer) args = {:params => {:q => query, :g => granularity, :n => 'Unknown', :s => options[:start_time].to_i, :e => options[:end_time].to_i, :strict => options[:strict], :includeObsoleteMetrics => options[:includeObsoleteMetrics] }}.merge(@headers) if options[:passthru] args[:params].merge!(options[: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(options[:response_format].to_s.capitalize) return klass.new(response, options) end
Private Instance Methods
debug(enabled)
click to toggle source
# File lib/wavefront/client.rb, line 78 def debug(enabled) if enabled RestClient.log = 'stdout' end end