Class: Opentsdb::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/opentsdb/client.rb

Overview

ruby client for OpenTsdb HTTP API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
# File 'lib/opentsdb/client.rb', line 11

def initialize(options = {})
  @host = options.delete(:host) || Opentsdb.host
  @port = options.delete(:port) || Opentsdb.port
  @http = HttpClient.new
  @query_options = options
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/opentsdb/client.rb', line 9

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/opentsdb/client.rb', line 9

def port
  @port
end

#query_optionsObject (readonly)

Returns the value of attribute query_options.



9
10
11
# File 'lib/opentsdb/client.rb', line 9

def query_options
  @query_options
end

Instance Method Details

#parse_queriesObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opentsdb/client.rb', line 26

def parse_queries
  [].tap do |qs|
    query_options[:q].split(';').each do |q|
      query = QueryParser.parse(q)
      query.interval   = query_options[:interval]
      query.start_time = query_options[:begin].to_i
      query.end_time   = query_options[:end].to_i
      qs << query
    end
  end
end

#queryObject



18
19
20
21
22
23
24
# File 'lib/opentsdb/client.rb', line 18

def query
  [].tap do |data|
    parse_queries.each do |query_commad|
      data << post(query_uri, query_commad.to_json)
    end
  end
end