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

#alter_retention_policy, #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_admin_privileges, #grant_user_privileges, #list_user_grants, #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

#builder, #ping, #query, #version, #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



51
52
53
54
55
56
57
58
59
# File 'lib/influxdb/client.rb', line 51

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 = find_writer

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/influxdb/client.rb', line 8

def config
  @config
end

#writerObject (readonly)

Returns the value of attribute writer.



8
9
10
# File 'lib/influxdb/client.rb', line 8

def writer
  @writer
end

Instance Method Details

#stop!Object



61
62
63
64
# File 'lib/influxdb/client.rb', line 61

def stop!
  writer.worker.stop! if config.async?
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/influxdb/client.rb', line 66

def stopped?
  @stopped
end