Skip to content

Commit

Permalink
docs: Clarify how to use a client with InfluxDB 1.8 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Apr 16, 2020
1 parent 1c26fe7 commit 22a7acf
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## 1.3.0 [unreleased]

### Features

1. [#32](https://github.com/influxdata/influxdb-client-ruby/pull/32): Checks the health of a running InfluxDB instance by querying the /health

### Documentation

1. [#35](https://github.com/influxdata/influxdb-client-ruby/pull/35): Clarify how to use a client with InfluxDB 1.8

## 1.2.0 [2020-03-13]

### Features
Expand All @@ -13,7 +18,7 @@
### Security
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)

### Bugs
### Bug Fixes
1. [#22](https://github.com/influxdata/influxdb-client-ruby/pull/22): Fixed batch write
1. [#28](https://github.com/influxdata/influxdb-client-ruby/pull/28): Correctly parse CSV where multiple results include multiple tables
1. [#30](https://github.com/influxdata/influxdb-client-ruby/pull/30): Send Content-Type headers
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

This repository contains the reference Ruby client for the InfluxDB 2.0.

#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+. For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-ruby](https://github.com/influxdata/influxdb-ruby) client library.
#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+ ([see details](#influxdb-18-api-compatibility)). For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-ruby](https://github.com/influxdata/influxdb-ruby) client library.

## Installation

Expand Down Expand Up @@ -237,6 +237,20 @@ The time range could be specified as:

Server availability can be checked using the `client.health` method. That is equivalent of the [influx ping](https://v2.docs.influxdata.com/v2.0/reference/cli/influx/ping/).

### InfluxDB 1.8 API compatibility

[InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/latest/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.0. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.0 Cloud or open source.

The following forward compatible APIs are available:

| API | Endpoint | Description |
|:----------|:----------|:----------|
| [query_api.rb](lib/influxdb2/client/query_api.rb) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.0 API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |
| [write_api.rb](lib/influxdb2/client/write_api.rb) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.0 API |
| [health_api.rb](lib/influxdb2/client/health_api.rb) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance |

For detail info see [InfluxDB 1.8 example](examples/influxdb_18_example.rb).

## Local tests

```
Expand Down
35 changes: 35 additions & 0 deletions examples/influxdb_18_example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'influxdb2/client'

username = 'username'
password = 'password'

database = 'telegraf'
retention_policy = 'autogen'

bucket = "#{database}/#{retention_policy}"

client = InfluxDB2::Client.new('http://localhost:8086',
"#{username}:#{password}",
bucket: bucket,
org: '-',
use_ssl: false,
precision: InfluxDB2::WritePrecision::NANOSECOND)

puts '*** Write Points ***'

write_api = client.create_write_api
point = InfluxDB2::Point.new(name: 'mem')
.add_tag('host', 'host1')
.add_field('used_percent', 21.43234543)
puts point.to_line_protocol
write_api.write(data: point)

puts '*** Query Points ***'

query_api = client.create_query_api
query = "from(bucket: \"#{bucket}\") |> range(start: -1h)"
result = query_api.query(query: query)
result[0].records.each { |record| puts "#{record.time} #{record.measurement}: #{record.field} #{record.value}" }

client.close!

0 comments on commit 22a7acf

Please sign in to comment.