Class: Opentsdb::Client
- Inherits:
-
Object
- Object
- Opentsdb::Client
- Extended by:
- Forwardable
- Defined in:
- lib/opentsdb/client.rb
Overview
ruby client for OpenTsdb HTTP API
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#query_commads ⇒ Object
Returns the value of attribute query_commads.
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #parse_queries ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 |
# File 'lib/opentsdb/client.rb', line 11 def initialize( = {}) @host = .delete(:host) || Opentsdb.host @port = .delete(:port) || Opentsdb.port = .merge(Opentsdb.) @faraday = Opentsdb::Faraday.new(query_url, ) @query_commads = parse_queries end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/opentsdb/client.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/opentsdb/client.rb', line 8 def port @port end |
#query_commads ⇒ Object
Returns the value of attribute query_commads.
9 10 11 |
# File 'lib/opentsdb/client.rb', line 9 def query_commads @query_commads end |
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
8 9 10 |
# File 'lib/opentsdb/client.rb', line 8 def end |
Instance Method Details
#parse_queries ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/opentsdb/client.rb', line 33 def parse_queries [].tap do |qs| [:q].split(';').each do |q| query = QueryParser.parse(q) query.interval = [:interval] query.start_time = [:begin].to_i query.end_time = [:end].to_i qs << query end end end |
#query ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opentsdb/client.rb', line 19 def query [].tap do |results| query_commads.each do |query_commad| start = Time.now Opentsdb.logger.debug "[OpenTSDB] query: #{query_commad.to_json}" res = post query_commad.to_json Opentsdb.logger.debug "[OpenTSDB] result: #{res.body}" Opentsdb.logger.info "[OpenTSDB] consume: #{Time.now - start} s" status = res.status.to_i == 200 ? 'ok' : 'error' results << { status: status, condition: query_commad, result: res.body } end end end |