Class: InfluxDB::Client

Inherits:
Object
  • Object
show all
Includes:
HTTP, Logging, Query::Cluster, Query::ContinuousQuery, Query::Core, Query::Database, Query::Measurement, Query::RetentionPolicy, Query::Series, 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::Measurement

#delete_measurement, #list_measurements

Methods included from Query::Series

#delete_series, #list_series

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, #show_field_keys

Methods included from Query::Cluster

#create_cluster_admin, #list_cluster_admins, #revoke_cluster_admin_privileges

Methods included from Query::Core

#batch, #builder, #ping, #query, #version, #write, #write_point, #write_points

Methods included from HTTP

#get, #post

Methods included from Logging

log?

Constructor Details

#initialize(database = nil, **opts) ⇒ 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

:retry

number of times a failed request should be retried. Defaults to infinite.



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

def initialize(database = nil, **opts)
  opts[:database] = database if database.is_a? String
  @config = InfluxDB::Config.new(**opts)
  @stopped = false
  @writer = find_writer

  at_exit { stop! }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/influxdb/client.rb', line 6

def config
  @config
end

#writerObject (readonly)

Returns the value of attribute writer.



6
7
8
# File 'lib/influxdb/client.rb', line 6

def writer
  @writer
end

Instance Method Details

#nowObject



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

def now
  InfluxDB.now(config.time_precision)
end

#stop!Object



61
62
63
64
65
66
67
68
69
# File 'lib/influxdb/client.rb', line 61

def stop!
  if config.async?
    # If retry was infinite (-1), set it to zero to give the main thread one
    # last chance to flush the queue
    config.retry = 0 if config.retry < 0
    writer.worker.stop!
  end
  @stopped = true
end

#stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  @stopped
end