influxdb-client 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +27 -0
- data/Gemfile +24 -0
- data/LICENSE +21 -0
- data/README.md +248 -0
- data/Rakefile +37 -0
- data/bin/generate-sources.sh +23 -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 +29 -0
- data/lib/influxdb2/client/client.rb +89 -0
- data/lib/influxdb2/client/default_api.rb +87 -0
- data/lib/influxdb2/client/delete_api.rb +80 -0
- data/lib/influxdb2/client/flux_csv_parser.rb +251 -0
- data/lib/influxdb2/client/flux_table.rb +99 -0
- data/lib/influxdb2/client/influx_error.rb +31 -0
- data/lib/influxdb2/client/models/delete_predicate_request.rb +215 -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 +115 -0
- data/lib/influxdb2/client/write_api.rb +243 -0
- data/test/influxdb/client_test.rb +70 -0
- data/test/influxdb/delete_api_integration_test.rb +100 -0
- data/test/influxdb/delete_api_test.rb +121 -0
- data/test/influxdb/flux_csv_parser_test.rb +401 -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 +96 -0
- data/test/influxdb/write_api_batching_test.rb +292 -0
- data/test/influxdb/write_api_integration_test.rb +76 -0
- data/test/influxdb/write_api_test.rb +275 -0
- data/test/test_helper.rb +39 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0bef54ca002cca11fb29d73a4de5efaa081a800ebc6a284a7eca088bf7d257ea
|
4
|
+
data.tar.gz: 1ca91c0b690ee38c10e89cc41a178f071e244b7b85126a0fadb52315c9eb5a45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 849abb961288944fb762ec38a8bb7fdc4b51be0941a03547e8e23360aee98aedf78018e98f75bb879497784bf75a6df3f5c80f164c2a9a453a466f5b8e890d7d
|
7
|
+
data.tar.gz: 2f9a75a9913f0f719d4dce37b1dfa33527159c0435672473979562aba705f8bf1ce34e1be5bd27bfd5dd713af41e39cf194460859a3631d6b28ededb9d188588
|
@@ -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: 50
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Max: 200
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 40
|
35
|
+
Metrics/CyclomaticComplexity:
|
36
|
+
Max: 15
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Max: 15
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## 1.2.0 [2020-03-13]
|
2
|
+
|
3
|
+
### Features
|
4
|
+
1. [#23](https://github.com/influxdata/influxdb-client-ruby/issues/23): Added DeleteApi to delete time series data from InfluxDB.
|
5
|
+
1. [#24](https://github.com/influxdata/influxdb-client-ruby/issues/24): Added jitter_interval and retry_interval to WriteApi
|
6
|
+
1. [#26](https://github.com/influxdata/influxdb-client-ruby/issues/26): Set User-Agent to influxdb-client-ruby/VERSION for all requests
|
7
|
+
|
8
|
+
### Security
|
9
|
+
1. [#29](https://github.com/influxdata/influxdb-client-ruby/pull/29): Upgrade rake to version 12.3.3 - [CVE-2020-8130](https://github.com/advisories/GHSA-jppv-gw3r-w3q8)
|
10
|
+
|
11
|
+
### Bugs
|
12
|
+
1. [#22](https://github.com/influxdata/influxdb-client-ruby/pull/22): Fixed batch write
|
13
|
+
1. [#28](https://github.com/influxdata/influxdb-client-ruby/pull/28): Correctly parse CSV where multiple results include multiple tables
|
14
|
+
1. [#30](https://github.com/influxdata/influxdb-client-ruby/pull/30): Send Content-Type headers
|
15
|
+
|
16
|
+
## 1.1.0 [2020-02-14]
|
17
|
+
|
18
|
+
### Features
|
19
|
+
1. [#14](https://github.com/influxdata/influxdb-client-ruby/issues/14): Added QueryApi
|
20
|
+
2. [#17](https://github.com/influxdata/influxdb-client-ruby/issues/17): Added possibility to stream query result
|
21
|
+
3. [#19](https://github.com/influxdata/influxdb-client-ruby/issues/19): Added WriteOptions and possibility to batch write
|
22
|
+
|
23
|
+
## 1.0.0.beta [2020-01-17]
|
24
|
+
|
25
|
+
### Features
|
26
|
+
1. [#4](https://github.com/influxdata/influxdb-client-ruby/pull/4): Added WriteApi that will be used for Fluentd plugin
|
27
|
+
|
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,248 @@
|
|
1
|
+
# influxdb-client-ruby
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/influxdata/influxdb-client-ruby)
|
4
|
+
[](https://codecov.io/gh/influxdata/influxdb-client-ruby)
|
5
|
+
[](https://badge.fury.io/rb/influxdb-client)
|
6
|
+
[](https://github.com/influxdata/influxdb-client-ruby/blob/master/LICENSE)
|
7
|
+
[](https://github.com/influxdata/influxdb-client-ruby/issues)
|
8
|
+
[](https://github.com/influxdata/influxdb-client-ruby/pulls)
|
9
|
+
[](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
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
The InfluxDB 2 client is bundled as a gem and is hosted on [Rubygems](https://rubygems.org/gems/influxdb-client).
|
18
|
+
|
19
|
+
### Install the Gem
|
20
|
+
|
21
|
+
The client can be installed manually or with bundler.
|
22
|
+
|
23
|
+
To install the client gem manually:
|
24
|
+
|
25
|
+
```
|
26
|
+
gem install influxdb-client -v 1.2.0
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Creating a client
|
32
|
+
|
33
|
+
Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
37
|
+
```
|
38
|
+
|
39
|
+
#### Client Options
|
40
|
+
|
41
|
+
| Option | Description | Type | Default |
|
42
|
+
|---|---|---|---|
|
43
|
+
| bucket | Default destination bucket for writes | String | none |
|
44
|
+
| org | Default organization bucket for writes | String | none |
|
45
|
+
| precision | Default precision for the unix timestamps within the body line-protocol | String | none |
|
46
|
+
| open_timeout | Number of seconds to wait for the connection to open | Integer | 10 |
|
47
|
+
| write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
|
48
|
+
| read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
|
49
|
+
| max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
|
50
|
+
| use_ssl | Turn on/off SSL for HTTP communication | bool | true |
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
54
|
+
bucket: 'my-bucket',
|
55
|
+
org: 'my-org',
|
56
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
57
|
+
```
|
58
|
+
|
59
|
+
### Queries
|
60
|
+
|
61
|
+
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:
|
62
|
+
|
63
|
+
1. Raw query response
|
64
|
+
2. Flux data structure: [FluxTable, FluxColumn and FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
65
|
+
3. Stream of [FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
|
66
|
+
|
67
|
+
#### Query raw
|
68
|
+
|
69
|
+
Synchronously executes the Flux query and return result as unprocessed String
|
70
|
+
```ruby
|
71
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
72
|
+
bucket: 'my-bucket',
|
73
|
+
org: 'my-org')
|
74
|
+
|
75
|
+
query_api = client.create_query_api
|
76
|
+
result = query_api.query_raw(query: 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
|
77
|
+
```
|
78
|
+
#### Synchronous query
|
79
|
+
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)
|
80
|
+
```ruby
|
81
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
82
|
+
bucket: 'my-bucket',
|
83
|
+
org: 'my-org')
|
84
|
+
|
85
|
+
query_api = client.create_query_api
|
86
|
+
result = query_api.query(query: 'from(bucket:"' + bucket + '") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Query stream
|
90
|
+
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)
|
91
|
+
```ruby
|
92
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
93
|
+
bucket: 'my-bucket',
|
94
|
+
org: 'my-org')
|
95
|
+
|
96
|
+
query_api = client.create_query_api
|
97
|
+
|
98
|
+
query = 'from(bucket: "my-bucket") |> range(start: -10m, stop: now()) ' \
|
99
|
+
"|> filter(fn: (r) => r._measurement == \"#{measurement}\")"
|
100
|
+
|
101
|
+
query_api.query_stream(query: query).each do |record|
|
102
|
+
puts record.to_s
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
### Writing data
|
107
|
+
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.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
111
|
+
bucket: 'my-bucket',
|
112
|
+
org: 'my-org',
|
113
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
114
|
+
|
115
|
+
write_api = client.create_write_api
|
116
|
+
write_api.write(data: 'h2o,location=west value=33i 15')
|
117
|
+
```
|
118
|
+
|
119
|
+
#### Batching
|
120
|
+
The writes are processed in batches which are configurable by `WriteOptions`:
|
121
|
+
|
122
|
+
| Property | Description | Default Value |
|
123
|
+
| --- | --- | --- |
|
124
|
+
| batchSize | the number of data point to collect in batch | 1000 |
|
125
|
+
| flushInterval | the number of milliseconds before the batch is written | 1000 |
|
126
|
+
| retry_interval | the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify "Retry-After" header. | 1000 |
|
127
|
+
| jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
131
|
+
batch_size: 10, flush_interval: 5_000)
|
132
|
+
client = InfluxDB2::Client.new('http://localhost:9999',
|
133
|
+
'my-token',
|
134
|
+
bucket: 'my-bucket',
|
135
|
+
org: 'my-org',
|
136
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
137
|
+
use_ssl: false)
|
138
|
+
|
139
|
+
write_api = client.create_write_api(write_options: write_options)
|
140
|
+
write_api.write(data: 'h2o,location=west value=33i 15')
|
141
|
+
```
|
142
|
+
|
143
|
+
#### Time precision
|
144
|
+
|
145
|
+
Configure default time precision:
|
146
|
+
```ruby
|
147
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
148
|
+
bucket: 'my-bucket',
|
149
|
+
org: 'my-org',
|
150
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
151
|
+
```
|
152
|
+
|
153
|
+
Configure precision per write:
|
154
|
+
```ruby
|
155
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
156
|
+
bucket: 'my-bucket',
|
157
|
+
org: 'my-org')
|
158
|
+
|
159
|
+
write_api = client.create_write_api
|
160
|
+
write_api.write(data: 'h2o,location=west value=33i 15', precision: InfluxDB2::WritePrecision::SECOND)
|
161
|
+
```
|
162
|
+
Allowed values for precision are:
|
163
|
+
- `InfluxDB::WritePrecision::NANOSECOND` for nanosecond
|
164
|
+
- `InfluxDB::WritePrecision::MICROSECOND` for microsecond
|
165
|
+
- `InfluxDB::WritePrecision::MILLISECOND` for millisecond
|
166
|
+
- `InfluxDB::WritePrecision::SECOND` for second
|
167
|
+
|
168
|
+
#### Configure destination
|
169
|
+
|
170
|
+
Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
|
171
|
+
```ruby
|
172
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
173
|
+
bucket: 'my-bucket',
|
174
|
+
org: 'my-org')
|
175
|
+
```
|
176
|
+
|
177
|
+
but there is also possibility to override configuration per write:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
181
|
+
|
182
|
+
write_api = client.create_write_api
|
183
|
+
write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
|
184
|
+
```
|
185
|
+
|
186
|
+
#### Data format
|
187
|
+
|
188
|
+
The data could be written as:
|
189
|
+
|
190
|
+
1. `String` that is formatted as a InfluxDB's line protocol
|
191
|
+
1. `Hash` with keys: name, tags, fields and time
|
192
|
+
1. [Data Point](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb/client/point.rb#L28) structure
|
193
|
+
1. `Array` of above items
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
197
|
+
bucket: 'my-bucket',
|
198
|
+
org: 'my-org',
|
199
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
200
|
+
|
201
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
202
|
+
.add_tag('location', 'europe')
|
203
|
+
.add_field('level', 2)
|
204
|
+
|
205
|
+
hash = { name: 'h2o',
|
206
|
+
tags: { host: 'aws', region: 'us' },
|
207
|
+
fields: { level: 5, saturation: '99%' }, time: 123 }
|
208
|
+
|
209
|
+
write_api = client.create_write_api
|
210
|
+
write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
|
211
|
+
```
|
212
|
+
|
213
|
+
### Delete data
|
214
|
+
|
215
|
+
The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://v2.docs.influxdata.com/v2.0/reference/glossary/#point) from an InfluxDB bucket.
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
219
|
+
bucket: 'my-bucket',
|
220
|
+
org: 'my-org',
|
221
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
222
|
+
|
223
|
+
client.create_delete_api.delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'),
|
224
|
+
DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
|
225
|
+
predicate: 'key1="value1" AND key2="value"')
|
226
|
+
```
|
227
|
+
|
228
|
+
The time range could be specified as:
|
229
|
+
|
230
|
+
1. String - `"2019-02-03T04:05:06+07:00"`
|
231
|
+
1. DateTime - `DateTime.rfc3339('2019-03-03T04:05:06+07:00')`
|
232
|
+
1. Time - `Time.utc(2015, 10, 16, 8, 20, 15)`
|
233
|
+
|
234
|
+
## Local tests
|
235
|
+
|
236
|
+
```
|
237
|
+
brew install wget # on a mac, if not yet installed!
|
238
|
+
bin/influxdb-restart.sh
|
239
|
+
rake test
|
240
|
+
```
|
241
|
+
|
242
|
+
## Contributing
|
243
|
+
|
244
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/influxdata/influxdb-client-ruby.
|
245
|
+
|
246
|
+
## License
|
247
|
+
|
248
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|