class OpenTSDBConsumer::Client

Attributes

connection[R]
host[R]
port[R]

Public Class Methods

new(host: 'localhost', port: 4242, options: {}) click to toggle source
# File lib/opentsdb-consumer/client.rb, line 12
def initialize(host: 'localhost', port: 4242, options: {})
  @host = host
  @port = port
  @connection = Excon.new url, options
end

Public Instance Methods

fetch(metric_names, options = {}) click to toggle source
# File lib/opentsdb-consumer/client.rb, line 18
def fetch(metric_names, options = {})
  options = {
    start: '8h-ago',
    aggregator: 'sum',
    downsample: '5m-avg',
    rate: false,
    tags: {},
  }.merge(options)

  metrics = build_metrics(metric_names, options)

  Query.new(metrics, self).run(start: options[:start])
end
url() click to toggle source
# File lib/opentsdb-consumer/client.rb, line 32
def url
  "http://#{host}:#{port}/api/query"
end

Private Instance Methods

build_metrics(metric_names, options) click to toggle source
# File lib/opentsdb-consumer/client.rb, line 38
def build_metrics(metric_names, options)
  metric_names.map do |metric|
    Metric.new(whitelisted_metric_options(options).merge(name: metric))
  end
end
whitelisted_metric_options(options) click to toggle source
# File lib/opentsdb-consumer/client.rb, line 44
def whitelisted_metric_options(options)
  options.select { |key, _| Metric::ATTRIBUTES_WHITELIST.include?(key) }
end