Class: InfluxDB::Client

Inherits:
Object
  • Object
show all
Includes:
HTTP, Logging, Query::Cluster, Query::ContinuousQuery, Query::Core, Query::Database, Query::RetentionPolicy, Query::User
Defined in:
lib/influxdb/client.rb

Overview

InfluxDB client class

Constant Summary

Constants included from Logging

Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Query::RetentionPolicy

#create_retention_policy, #delete_retention_policy, #list_retention_policies

Methods included from Query::ContinuousQuery

#create_continuous_query, #delete_continuous_query, #list_continuous_queries

Methods included from Query::User

#create_database_user, #delete_user, #grant_user_privileges, #list_users, #revoke_user_privileges, #update_user_password

Methods included from Query::Database

#create_database, #delete_database, #list_databases

Methods included from Query::Cluster

#create_cluster_admin, #list_cluster_admins, #revoke_cluster_admin_privileges

Methods included from Query::Core

#ping, #query, #write, #write_point, #write_points

Methods included from HTTP

#get, #post

Constructor Details

#initialize(*args) ⇒ Client

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

:prefix

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

:verify_ssl

verify ssl server certificate?

:ssl_ca_cert

ssl CA certificate, chainfile or CA path. The system CA path is automatically included



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/influxdb/client.rb', line 53

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/influxdb/client.rb', line 10

def config
  @config
end

#writerObject (readonly)

Returns the value of attribute writer.



10
11
12
# File 'lib/influxdb/client.rb', line 10

def writer
  @writer
end

Instance Method Details

#stop!Object



70
71
72
# File 'lib/influxdb/client.rb', line 70

def stop!
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/influxdb/client.rb', line 74

def stopped?
  @stopped
end