Module: InfluxDB

Defined in:
lib/influxdb/errors.rb,
lib/influxdb/client.rb,
lib/influxdb/config.rb,
lib/influxdb/logging.rb,
lib/influxdb/version.rb,
lib/influxdb/max_queue.rb,
lib/influxdb/query/core.rb,
lib/influxdb/query/user.rb,
lib/influxdb/writer/udp.rb,
lib/influxdb/client/http.rb,
lib/influxdb/point_value.rb,
lib/influxdb/query/batch.rb,
lib/influxdb/query/series.rb,
lib/influxdb/writer/async.rb,
lib/influxdb/query/builder.rb,
lib/influxdb/query/cluster.rb,
lib/influxdb/query/database.rb,
lib/influxdb/query/measurement.rb,
lib/influxdb/timestamp_conversion.rb,
lib/influxdb/query/continuous_query.rb,
lib/influxdb/query/retention_policy.rb

Overview

:nodoc:

Defined Under Namespace

Modules: HTTP, Logging, Query, Writer Classes: Client, Config, MaxQueue, PointValue

Constant Summary collapse

DEFAULT_CONFIG_OPTIONS =

DEFAULT_CONFIG_OPTIONS maps (most) of the configuration options to their default value. Each option (except for “async” and “udp”) can be changed at runtime throug the InfluxDB::Client instance.

If you need to change the writer to be asynchronuous or use UDP, you need to get a new InfluxDB::Client instance.

{
  # HTTP connection options
  port:                 8086,
  prefix:               "".freeze,
  username:             "root".freeze,
  password:             "root".freeze,
  open_timeout:         5,
  read_timeout:         300,
  auth_method:          nil,

  # SSL options
  use_ssl:              false,
  verify_ssl:           true,
  ssl_ca_cert:          false,

  # Database options
  database:             nil,
  time_precision:       "s".freeze,
  epoch:                false,

  # Writer options
  async:                false,
  udp:                  false,
  discard_write_errors: false,

  # Retry options
  retry:                -1,
  max_delay:            30,
  initial_delay:        0.01,

  # Query options
  chunk_size:           nil,
  denormalize:          true,
}.freeze
Error =
Class.new StandardError
AuthenticationError =
Class.new Error
ConnectionError =
Class.new Error
SeriesNotFound =
Class.new Error
JSONParserError =
Class.new Error
QueryError =
Class.new Error
RECOVERABLE_EXCEPTIONS =

When executing queries via HTTP, some errors can more or less safely be ignored and we can retry the query again. This following exception classes shall be deemed as “safe”.

Taken from: github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb

[
  Errno::ECONNABORTED,
  Errno::ECONNREFUSED,
  Errno::ECONNRESET,
  Errno::EHOSTUNREACH,
  Errno::EINVAL,
  Errno::ENETUNREACH,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  SocketError,
  (OpenSSL::SSL::SSLError if defined?(OpenSSL)),
].compact.freeze
NON_RECOVERABLE_EXCEPTIONS =

Exception classes which hint to a larger problem on the server side, like insuffient resources. If we encouter on of the following, wo _don’t_ retry a query but escalate it upwards.

[
  EOFError,
  Zlib::Error,
].freeze
NON_RECOVERABLE_MESSAGE =
"The server has sent incomplete data" \
" (insufficient resources are a possible cause).".freeze
VERSION =
"0.7.0".freeze

Class Method Summary collapse

Class Method Details

.convert_timestamp(time, precision = "s") ⇒ Object

Converts a Time to a timestamp with the given precision.

Example

InfluxDB.convert_timestamp(Time.now, "ms")
#=> 1543533308243


8
9
10
11
12
13
14
# File 'lib/influxdb/timestamp_conversion.rb', line 8

def self.convert_timestamp(time, precision = "s")
  factor = TIME_PRECISION_FACTORS.fetch(precision) do
    raise ArgumentError, "invalid time precision: #{precision}"
  end

  (time.to_r * factor).to_i
end

.now(precision = "s") ⇒ Object

Returns the current timestamp with the given precision.

Implementation detail: This does not create an intermediate Time object with ‘Time.now`, but directly requests the CLOCK_REALTIME, which in general is a bit faster.

This is useful, if you want or need to shave off a few microseconds from your measurement.

Examples

InfluxDB.now("ns")   #=> 1543612126401392625
InfluxDB.now("u")    #=> 1543612126401392
InfluxDB.now("ms")   #=> 1543612126401
InfluxDB.now("s")    #=> 1543612126
InfluxDB.now("m")    #=> 25726868
InfluxDB.now("h")    #=> 428781


33
34
35
36
37
38
39
40
# File 'lib/influxdb/timestamp_conversion.rb', line 33

def self.now(precision = "s")
  name, divisor = CLOCK_NAMES.fetch(precision) do
    raise ArgumentError, "invalid time precision: #{precision}"
  end

  time = Process.clock_gettime Process::CLOCK_REALTIME, name
  (time / divisor).to_i
end