influxdb-client 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +157 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.codecov.yml +3 -0
- data/.github/PULL_REQUEST_TEMPLATE +8 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +38 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +24 -0
- data/LICENSE +21 -0
- data/README.md +226 -0
- data/Rakefile +37 -0
- data/bin/generate-sources.sh +30 -0
- data/bin/influxdb-onboarding.sh +39 -0
- data/bin/influxdb-restart.sh +60 -0
- data/bin/pom.xml +34 -0
- data/bin/swagger.yml +9867 -0
- data/influxdb-client.gemspec +53 -0
- data/lib/influxdb2/client.rb +28 -0
- data/lib/influxdb2/client/client.rb +82 -0
- data/lib/influxdb2/client/default_api.rb +68 -0
- data/lib/influxdb2/client/flux_csv_parser.rb +246 -0
- data/lib/influxdb2/client/flux_table.rb +99 -0
- data/lib/influxdb2/client/influx_error.rb +27 -0
- data/lib/influxdb2/client/models/dialect.rb +317 -0
- data/lib/influxdb2/client/models/query.rb +284 -0
- data/lib/influxdb2/client/point.rb +215 -0
- data/lib/influxdb2/client/query_api.rb +93 -0
- data/lib/influxdb2/client/version.rb +23 -0
- data/lib/influxdb2/client/worker.rb +89 -0
- data/lib/influxdb2/client/write_api.rb +219 -0
- data/test/influxdb/client_test.rb +70 -0
- data/test/influxdb/flux_csv_parser_test.rb +326 -0
- data/test/influxdb/point_test.rb +221 -0
- data/test/influxdb/query_api_integration_test.rb +58 -0
- data/test/influxdb/query_api_stream_test.rb +98 -0
- data/test/influxdb/query_api_test.rb +75 -0
- data/test/influxdb/write_api_batching_test.rb +153 -0
- data/test/influxdb/write_api_integration_test.rb +75 -0
- data/test/influxdb/write_api_test.rb +235 -0
- data/test/test_helper.rb +39 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c567a9747fbb62687569311a2a23d75115eab950713766a8a7e8ac0a65d8a7b
|
4
|
+
data.tar.gz: 1fdb87086e8f18ff65d2da79a51d34c397887bc6ad0ae87dd3904b3cbb1787e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbc770f809525bd1799e1698d4c8214893a4364f9563fcb972e47f5446720cbbfda6e07acdb0c253b2cad0c6d86decda03fbdcb8ac5639f3428a4362f2f59819
|
7
|
+
data.tar.gz: 3469d334c5fe3bade7cca71291db812f617a56231a8a6a5abe309b2ecb97a381a6f547df81699da7ba0a8c67b20742a620cba020b2bed366802a259463881df0
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
version: 2.1
|
24
|
+
|
25
|
+
commands:
|
26
|
+
influxdb-onboarding:
|
27
|
+
steps:
|
28
|
+
- run:
|
29
|
+
name: "Post onBoarding request to InfluxDB 2"
|
30
|
+
command: ./bin/influxdb-onboarding.sh
|
31
|
+
prepare:
|
32
|
+
description: "Prepare environment to tests"
|
33
|
+
steps:
|
34
|
+
- checkout
|
35
|
+
- influxdb-onboarding
|
36
|
+
test:
|
37
|
+
parameters:
|
38
|
+
ruby-image:
|
39
|
+
type: string
|
40
|
+
steps:
|
41
|
+
- restore_cache:
|
42
|
+
name: Restoring Gem Cache
|
43
|
+
keys:
|
44
|
+
- &cache-key gem-cache-{{ checksum "influxdb-client.gemspec" }}-<< parameters.ruby-image >>
|
45
|
+
- gem-cache-{{ checksum "influxdb-client.gemspec" }}
|
46
|
+
- gem-cache-
|
47
|
+
- run:
|
48
|
+
name: Install dependencies
|
49
|
+
command: |
|
50
|
+
gem install bundler
|
51
|
+
bundle config set path 'vendor/bundle'
|
52
|
+
bundle install --jobs=4 --retry=3
|
53
|
+
- run:
|
54
|
+
name: Static code analyze
|
55
|
+
command: |
|
56
|
+
bundle exec rake rubocop
|
57
|
+
- run:
|
58
|
+
name: Run tests
|
59
|
+
command: |
|
60
|
+
export MINITEST_REPORTER=JUnitReporter
|
61
|
+
bundle exec rake test
|
62
|
+
- save_cache:
|
63
|
+
name: Saving Gem Cache
|
64
|
+
key: *cache-key
|
65
|
+
paths:
|
66
|
+
- ./vendor/bundle
|
67
|
+
when: always
|
68
|
+
storing-test-results:
|
69
|
+
steps:
|
70
|
+
- store_test_results:
|
71
|
+
path: test/reports
|
72
|
+
|
73
|
+
jobs:
|
74
|
+
tests-ruby:
|
75
|
+
parameters:
|
76
|
+
ruby-image:
|
77
|
+
type: string
|
78
|
+
default: &default-ruby-image "circleci/ruby:2.6-stretch"
|
79
|
+
influxdb-image:
|
80
|
+
type: string
|
81
|
+
default: &default-influxdb-image "influxdb:2.0.0-beta"
|
82
|
+
docker:
|
83
|
+
- image: << parameters.ruby-image >>
|
84
|
+
- image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >>
|
85
|
+
steps:
|
86
|
+
- prepare
|
87
|
+
- test:
|
88
|
+
ruby-image: << parameters.ruby-image >>
|
89
|
+
- storing-test-results
|
90
|
+
|
91
|
+
deploy-preview:
|
92
|
+
parameters:
|
93
|
+
influxdb-image:
|
94
|
+
type: string
|
95
|
+
default: *default-influxdb-image
|
96
|
+
docker:
|
97
|
+
- image: *default-ruby-image
|
98
|
+
- image: *influx-image
|
99
|
+
steps:
|
100
|
+
- run:
|
101
|
+
name: Early return if this build is from a forked repository
|
102
|
+
command: |
|
103
|
+
if [[ $CIRCLE_PROJECT_USERNAME != "influxdata" ]]; then
|
104
|
+
echo "Nothing to do for forked repositories, so marking this step successful"
|
105
|
+
circleci step halt
|
106
|
+
fi
|
107
|
+
- checkout
|
108
|
+
- run:
|
109
|
+
name: Setup Rubygems
|
110
|
+
command: bash .circleci/setup-rubygems.sh
|
111
|
+
- run:
|
112
|
+
name: Build a Gem bundle
|
113
|
+
command: |
|
114
|
+
gem build influxdb-client.gemspec
|
115
|
+
- run:
|
116
|
+
name: Deploy pre-release into https://rubygems.org
|
117
|
+
command: |
|
118
|
+
gem push influxdb-client-*.pre.$CIRCLE_BUILD_NUM.gem
|
119
|
+
workflows:
|
120
|
+
version: 2
|
121
|
+
build:
|
122
|
+
jobs:
|
123
|
+
- tests-ruby:
|
124
|
+
name: ruby-2.7
|
125
|
+
ruby-image: "circleci/ruby:2.7-buster"
|
126
|
+
- tests-ruby:
|
127
|
+
name: ruby-2.6
|
128
|
+
- tests-ruby:
|
129
|
+
name: ruby-2.6-nightly
|
130
|
+
influxdb-image: "influx:nightly"
|
131
|
+
- tests-ruby:
|
132
|
+
name: ruby-2.5
|
133
|
+
ruby-image: "circleci/ruby:2.5-stretch"
|
134
|
+
- tests-ruby:
|
135
|
+
name: ruby-2.4
|
136
|
+
ruby-image: "circleci/ruby:2.4-stretch"
|
137
|
+
- deploy-preview:
|
138
|
+
requires:
|
139
|
+
- ruby-2.7
|
140
|
+
- ruby-2.6
|
141
|
+
- ruby-2.6-nightly
|
142
|
+
- ruby-2.5
|
143
|
+
- ruby-2.4
|
144
|
+
filters:
|
145
|
+
branches:
|
146
|
+
only: master
|
147
|
+
|
148
|
+
nightly:
|
149
|
+
triggers:
|
150
|
+
- schedule:
|
151
|
+
cron: "0 0 * * *"
|
152
|
+
filters:
|
153
|
+
branches:
|
154
|
+
only:
|
155
|
+
- master
|
156
|
+
jobs:
|
157
|
+
- tests-ruby
|
data/.codecov.yml
ADDED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# The MIT License
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
|
23
|
+
AllCops:
|
24
|
+
Exclude:
|
25
|
+
- 'lib/influxdb2/client/models/**/*'
|
26
|
+
- 'vendor/**/*'
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 120
|
29
|
+
Metrics/MethodLength:
|
30
|
+
Max: 30
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Max: 200
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 30
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Max: 15
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Max: 15
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## 1.1.0 [2020-02-14]
|
2
|
+
|
3
|
+
### Features
|
4
|
+
1. [#14](https://github.com/influxdata/influxdb-client-ruby/issues/14): Added QueryApi
|
5
|
+
2. [#17](https://github.com/influxdata/influxdb-client-ruby/issues/17): Added possibility to stream query result
|
6
|
+
3. [#19](https://github.com/influxdata/influxdb-client-ruby/issues/19): Added WriteOptions and possibility to batch write
|
7
|
+
|
8
|
+
## 1.0.0.beta [2020-01-17]
|
9
|
+
|
10
|
+
### Features
|
11
|
+
1. [#4](https://github.com/influxdata/influxdb-client-ruby/pull/4): Added WriteApi that will be used for Fluentd plugin
|
12
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
source 'https://rubygems.org'
|
22
|
+
|
23
|
+
# Specify your gem's dependencies in influxdb-client.gemspec
|
24
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Influxdata, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
# influxdb-client-ruby
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/influxdata/influxdb-client-ruby.svg?style=svg)](https://circleci.com/gh/influxdata/influxdb-client-ruby)
|
4
|
+
[![codecov](https://codecov.io/gh/influxdata/influxdb-client-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/influxdata/influxdb-client-ruby)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/influxdb-client.svg)](https://badge.fury.io/rb/influxdb-client)
|
6
|
+
[![License](https://img.shields.io/github/license/influxdata/influxdb-client-ruby.svg)](https://github.com/influxdata/influxdb-client-ruby/blob/master/LICENSE)
|
7
|
+
[![GitHub issues](https://img.shields.io/github/issues-raw/influxdata/influxdb-client-ruby.svg)](https://github.com/influxdata/influxdb-client-ruby/issues)
|
8
|
+
[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/influxdata/influxdb-client-ruby.svg)](https://github.com/influxdata/influxdb-client-ruby/pulls)
|
9
|
+
[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack&style=social)](https://www.influxdata.com/slack)
|
10
|
+
|
11
|
+
This repository contains the reference Ruby client for the InfluxDB 2.0.
|
12
|
+
|
13
|
+
#### Note: This library is for use with InfluxDB 2.x. For connecting to InfluxDB 1.x instances, please use the [influxdb-ruby](https://github.com/influxdata/influxdb-ruby) client.
|
14
|
+
#### Disclaimer: This library is a work in progress and should not be considered production ready yet.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
The InfluxDB 2 client is bundled as a gem and is hosted on [Rubygems](https://rubygems.org/gems/influxdb-client).
|
19
|
+
|
20
|
+
### Install the Gem
|
21
|
+
|
22
|
+
The client can be installed manually or with bundler.
|
23
|
+
|
24
|
+
To install the client gem manually:
|
25
|
+
|
26
|
+
```
|
27
|
+
gem install influxdb-client -v 1.1.0
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### Creating a client
|
33
|
+
|
34
|
+
Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Client Options
|
41
|
+
|
42
|
+
| Option | Description | Type | Default |
|
43
|
+
|---|---|---|---|
|
44
|
+
| bucket | Default destination bucket for writes | String | none |
|
45
|
+
| org | Default organization bucket for writes | String | none |
|
46
|
+
| precision | Default precision for the unix timestamps within the body line-protocol | String | none |
|
47
|
+
| open_timeout | Number of seconds to wait for the connection to open | Integer | 10 |
|
48
|
+
| write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
|
49
|
+
| read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
|
50
|
+
| max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
|
51
|
+
| use_ssl | Turn on/off SSL for HTTP communication | bool | true |
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
55
|
+
bucket: 'my-bucket',
|
56
|
+
org: 'my-org',
|
57
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
58
|
+
```
|
59
|
+
|
60
|
+
### Queries
|
61
|
+
|
62
|
+
The result retrieved by [QueryApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/query_api.rb) could be formatted as a:
|
63
|
+
|
64
|
+
1. Raw query response
|
65
|
+
2. Flux data structure: [FluxTable, FluxColumn and FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
66
|
+
3. Stream of [FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
67
|
+
|
68
|
+
#### Query raw
|
69
|
+
|
70
|
+
Synchronously executes the Flux query and return result as unprocessed String
|
71
|
+
```ruby
|
72
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
73
|
+
bucket: 'my-bucket',
|
74
|
+
org: 'my-org')
|
75
|
+
|
76
|
+
query_api = client.create_query_api
|
77
|
+
result = query_api.query_raw(query: 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
|
78
|
+
```
|
79
|
+
#### Synchronous query
|
80
|
+
Synchronously executes the Flux query and return result as a Array of [FluxTables](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
81
|
+
```ruby
|
82
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
83
|
+
bucket: 'my-bucket',
|
84
|
+
org: 'my-org')
|
85
|
+
|
86
|
+
query_api = client.create_query_api
|
87
|
+
result = query_api.query(query: 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Query stream
|
91
|
+
Synchronously executes the Flux query and return stream of [FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
92
|
+
```ruby
|
93
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
94
|
+
bucket: 'my-bucket',
|
95
|
+
org: 'my-org')
|
96
|
+
|
97
|
+
query_api = client.create_query_api
|
98
|
+
|
99
|
+
query = 'from(bucket: "my-bucket") |> range(start: -10m, stop: now()) ' \
|
100
|
+
"|> filter(fn: (r) => r._measurement == \"#{measurement}\")"
|
101
|
+
|
102
|
+
query_api.query_stream(query: query).each do |record|
|
103
|
+
puts record.to_s
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
### Writing data
|
108
|
+
The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.0. In default api uses synchronous write. To enable batching you can use WriteOption.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
112
|
+
bucket: 'my-bucket',
|
113
|
+
org: 'my-org',
|
114
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
115
|
+
|
116
|
+
write_api = client.create_write_api
|
117
|
+
write_api.write(data: 'h2o,location=west value=33i 15')
|
118
|
+
```
|
119
|
+
|
120
|
+
#### Batching
|
121
|
+
The writes are processed in batches which are configurable by `WriteOptions`:
|
122
|
+
|
123
|
+
| Property | Description | Default Value |
|
124
|
+
| --- | --- | --- |
|
125
|
+
| **batchSize** | the number of data point to collect in batch | 1000 |
|
126
|
+
| **flushInterval** | the number of milliseconds before the batch is written | 1000 |
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
130
|
+
batch_size: 10, flush_interval: 5_000)
|
131
|
+
client = InfluxDB2::Client.new('http://localhost:9999',
|
132
|
+
'my-token',
|
133
|
+
bucket: 'my-bucket',
|
134
|
+
org: 'my-org',
|
135
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
136
|
+
use_ssl: false)
|
137
|
+
|
138
|
+
write_api = client.create_write_api(write_options: write_options)
|
139
|
+
write_api.write(data: 'h2o,location=west value=33i 15')
|
140
|
+
```
|
141
|
+
|
142
|
+
#### Time precision
|
143
|
+
|
144
|
+
Configure default time precision:
|
145
|
+
```ruby
|
146
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
147
|
+
bucket: 'my-bucket',
|
148
|
+
org: 'my-org',
|
149
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
150
|
+
```
|
151
|
+
|
152
|
+
Configure precision per write:
|
153
|
+
```ruby
|
154
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
155
|
+
bucket: 'my-bucket',
|
156
|
+
org: 'my-org')
|
157
|
+
|
158
|
+
write_api = client.create_write_api
|
159
|
+
write_api.write(data: 'h2o,location=west value=33i 15', precision: InfluxDB2::WritePrecision::SECOND)
|
160
|
+
```
|
161
|
+
Allowed values for precision are:
|
162
|
+
- `InfluxDB::WritePrecision::NANOSECOND` for nanosecond
|
163
|
+
- `InfluxDB::WritePrecision::MICROSECOND` for microsecond
|
164
|
+
- `InfluxDB::WritePrecision::MILLISECOND` for millisecond
|
165
|
+
- `InfluxDB::WritePrecision::SECOND` for second
|
166
|
+
|
167
|
+
#### Configure destination
|
168
|
+
|
169
|
+
Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
|
170
|
+
```ruby
|
171
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
172
|
+
bucket: 'my-bucket',
|
173
|
+
org: 'my-org')
|
174
|
+
```
|
175
|
+
|
176
|
+
but there is also possibility to override configuration per write:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
180
|
+
|
181
|
+
write_api = client.create_write_api
|
182
|
+
write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
|
183
|
+
```
|
184
|
+
|
185
|
+
#### Data format
|
186
|
+
|
187
|
+
The data could be written as:
|
188
|
+
|
189
|
+
1. `String` that is formatted as a InfluxDB's line protocol
|
190
|
+
1. `Hash` with keys: name, tags, fields and time
|
191
|
+
1. [Data Point](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb/client/point.rb#L28) structure
|
192
|
+
1. `Array` of above items
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
196
|
+
bucket: 'my-bucket',
|
197
|
+
org: 'my-org',
|
198
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
199
|
+
|
200
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
201
|
+
.add_tag('location', 'europe')
|
202
|
+
.add_field('level', 2)
|
203
|
+
|
204
|
+
hash = { name: 'h2o',
|
205
|
+
tags: { host: 'aws', region: 'us' },
|
206
|
+
fields: { level: 5, saturation: '99%' }, time: 123 }
|
207
|
+
|
208
|
+
write_api = client.create_write_api
|
209
|
+
write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
|
210
|
+
```
|
211
|
+
|
212
|
+
## Local tests
|
213
|
+
|
214
|
+
```
|
215
|
+
brew install wget # on a mac, if not yet installed!
|
216
|
+
bin/influxdb-restart.sh
|
217
|
+
rake test
|
218
|
+
```
|
219
|
+
|
220
|
+
## Contributing
|
221
|
+
|
222
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/influxdata/influxdb-client-ruby.
|
223
|
+
|
224
|
+
## License
|
225
|
+
|
226
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|