Skip to content

kareem-abdelsalam/influxdb-ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

influxdb-ruby

Build Status

Ruby client library for InfluxDB.

Install

$ [sudo] gem install influxdb

Or add it to your Gemfile, etc.

Usage

Connecting to a single host:

require 'influxdb'

influxdb = InfluxDB::Client.new host: "influxdb.domain.com"

Connecting to multiple hosts (with built-in load balancing and failover):

require 'influxdb'

influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"]

Create a database:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.create_database(database)

Create a user for a database:

require 'influxdb'

influxdb = InfluxDB::Client.new

database = 'site_development'
new_username = 'foo'
new_password = 'bar'
influxdb.create_database_user(database, new_username, new_password)

Update a database user:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.update_database_user(database, username, :password => "new_password")

Write some data:

require 'influxdb'

username = 'foo'
password = 'bar'
database = 'site_development'
name     = 'foobar'

influxdb = InfluxDB::Client.new database, :username => username, :password => password

# Enumerator that emits a sine wave
Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each

loop do
  data = {
    :value => Value.next
  }

  influxdb.write_point(name, data)

  sleep 1
end

Write data with time precision:

Time precision can be set in 2 ways, either in the client initialization

require 'influxdb'

username = 'foo'
password = 'bar'
database = 'site_development'
name     = 'foobar'
time_precision = 's'

influxdb = InfluxDB::Client.new database, :username => username,
                                          :password => password, 
                                          :time_precision => time_precision

data = {
  :value => 0,
  :time => Time.now.to_i
}

influxdb.write_point(name, data)

or in the write call

require 'influxdb'

username = 'foo'
password = 'bar'
database = 'site_development'
name     = 'foobar'
time_precision = 's'

influxdb = InfluxDB::Client.new database, :username => username, :password => password

data = {
  :value => 0,
  :time => Time.now.to_i
}

influxdb.write_point(name, data, false, time_precision)

List cluster admins:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.get_cluster_admin_list

List databases:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.get_database_list

List database users:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.get_database_user_list(database)

List a database user:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.get_database_user_info(database, username)

Delete a database:

require 'influxdb'

influxdb = InfluxDB::Client.new

database = 'site_development'
influxdb.delete_database(database)

Delete a database user:

require 'influxdb'

influxdb = InfluxDB::Client.new

influxdb.delete_database_user(database, username)

Querying:

require 'influxdb'

username = 'foo'
password = 'bar'
database = 'site_development'

influxdb = InfluxDB::Client.new database, :username => username, :password => password

influxdb.query 'select * from time_series_1' do |name, points|
  puts "#{name} => #{points}"
end

Testing

git clone git@github.com:influxdb/influxdb-ruby.git
cd influxdb-ruby
bundle
bundle exec rake

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%