Module: InfluxDB::Query::Core

Included in:
Client
Defined in:
lib/influxdb/query/core.rb

Overview

rubocop:disable Metrics/AbcSize

Instance Method Summary collapse

Instance Method Details

#pingObject



5
6
7
# File 'lib/influxdb/query/core.rb', line 5

def ping
  get "/ping".freeze
end

#query(query, opts = {}) ⇒ Object

rubocop:disable Metrics/MethodLength



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/influxdb/query/core.rb', line 15

def query(query, opts = {})
  denormalize = opts.fetch(:denormalize, config.denormalize)
  params = query_params(query, opts)
  url = full_url("/query".freeze, params)
  series = fetch_series(get(url, parse: true))

  if block_given?
    series.each do |s|
      values = denormalize ? denormalize_series(s) : raw_values(s)
      yield s['name'.freeze], s['tags'.freeze], values
    end
  else
    denormalize ? denormalized_series_list(series) : series
  end
end

#versionObject



9
10
11
12
# File 'lib/influxdb/query/core.rb', line 9

def version
  resp = get "/ping".freeze
  resp.header['x-influxdb-version']
end

#write(data, precision, retention_policy = nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/influxdb/query/core.rb', line 57

def write(data, precision, retention_policy = nil)
  precision ||= config.time_precision
  params      = { db: config.database, precision: precision }
  params[:rp] = retention_policy if retention_policy
  url = full_url("/write", params)
  post(url, data)
end

#write_point(series, data, precision = nil, retention_policy = nil) ⇒ Object

Example: write_point(‘cpu’, tags: ‘us’, values: 60)



53
54
55
# File 'lib/influxdb/query/core.rb', line 53

def write_point(series, data, precision = nil, retention_policy = nil)
  write_points(data.merge(series: series), precision, retention_policy)
end

#write_points(data, precision = nil, retention_policy = nil) ⇒ Object

Example: write_points([

{
  series: 'cpu',
  tags: { host: 'server_nl', regios: 'us' },
  values: {internal: 5, external: 6},
  timestamp: 1422568543702900257
},
{
  series: 'gpu',
  values: {value: 0.9999},
}

])



45
46
47
48
49
# File 'lib/influxdb/query/core.rb', line 45

def write_points(data, precision = nil, retention_policy = nil)
  data = data.is_a?(Array) ? data : [data]
  payload = generate_payload(data)
  writer.write(payload, precision, retention_policy)
end