class InfluxDB::Client

InfluxDB client class

Attributes

config[R]
writer[R]

Public Class Methods

new(*args) click to toggle source

Initializes a new InfluxDB client

Examples:

# connect to localhost using root/root
# as the credentials and doesn't connect to a db

InfluxDB::Client.new

# connect to localhost using root/root
# as the credentials and 'db' as the db name

InfluxDB::Client.new 'db'

# override username, other defaults remain unchanged

InfluxDB::Client.new username: 'username'

# override username, use 'db' as the db name
Influxdb::Client.new 'db', username: 'username'

Valid options in hash

:host

the hostname to connect to

:port

the port to connect to

:path

the specified path prefix when building the url e.g.: /prefix/db/dbname…

:username

the username to use when executing commands

:password

the password associated with the username

:use_ssl

use ssl to connect

# File lib/influxdb/client.rb, line 52
def initialize(*args)
  opts = args.last.is_a?(Hash) ? args.last : {}
  opts[:database] = args.first if args.first.is_a? String
  @config = InfluxDB::Config.new(opts)
  @stopped = false

  @writer = self

  if config.async?
    @writer = InfluxDB::Writer::Async.new(self, config.async)
  elsif config.udp?
    @writer = InfluxDB::Writer::UDP.new(self, config.udp)
  end

  at_exit { stop! } if config.retry > 0
end

Public Instance Methods

stop!() click to toggle source
# File lib/influxdb/client.rb, line 69
def stop!
  @stopped = true
end
stopped?() click to toggle source
# File lib/influxdb/client.rb, line 73
def stopped?
  @stopped
end