Documentation

InfluxDB 1.x 兼容性 API

InfluxDB v2 API 包含与 InfluxDB 1.x 客户端库和第三方集成(如 Grafana 等)兼容的 InfluxDB 1.x 端点。

查看完整的 v1 兼容性 API 文档

认证

InfluxDB 1.x 兼容性端点要求所有查询和写入请求都经过认证,使用 API token 或 1.x 兼容的 凭据。

使用令牌方案进行身份验证

令牌认证需要以下凭据:

使用 Authorization 头与 Token 方案将您的令牌提供给 InfluxDB。

语法

Authorization: Token INFLUX_API_TOKEN

示例

#######################################
# Use a token in the Authorization header
# to query the InfluxDB 1.x compatibility API.
#
# Replace INFLUX_API_TOKEN with your InfluxDB API token.
#######################################

curl --get "http://localhost:8086" \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --header 'Content-type: application/json' \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM cpu_usage"
/**
  * Use the Token authentication scheme
  * to query the InfluxDB 1.x compatibility API.
  *
  * Replace INFLUX_API_TOKEN with your InfluxDB API token.
  */

const https = require('https');
const querystring = require('querystring');

function queryWithToken() {
  const queryparams = {
      db: 'mydb',
      q: 'SELECT * FROM cpu_usage',
  };

  const options = {
    host: 'localhost:8086',
    path: "/query?" + querystring.stringify(queryparams),
    headers: {
      'Authorization': 'Token INFLUX_API_TOKEN',
      'Content-type': 'application/json'
    },
  };

  const request = https.get(options, (response) => {
    let rawData = '';
    response.on('data', () => {
      response.on('data', (chunk) => { rawData += chunk; });
    })
    response.on('end', () => {
      console.log(rawData);
    })
  });

  request.end();
}

使用用户名和密码方案进行身份验证

使用以下认证方案与支持 InfluxDB 1.x 约定的客户端,即 usernamepassword(不支持 Authorization: Token 方案):

管理凭据

  • username: InfluxDB Cloud 用户名 (使用您注册时的电子邮件地址作为用户名,比如 exampleuser@influxdata.com.)
  • 密码: InfluxDB Cloud API token

基本认证

使用 Authorization 头与 Basic 方案提供用户名和密码凭据给 InfluxDB。

大多数HTTP客户端提供基本认证选项,该选项接受<username>:<password>语法,并在发送请求之前对凭据进行编码。

语法
Authorization: Basic exampleuser@influxdata.com:INFLUX_API_TOKEN
示例
#######################################
# Use an InfluxDB 1.x compatible username
# and password with Basic Authentication
# to query the InfluxDB 1.x compatibility API
#######################################
# Use default retention policy
#######################################
# Use the --user option with `--user 
INFLUX_USERNAME
:
INFLUX_API_TOKEN
` syntax
# or the `--user
INFLUX_USERNAME
` interactive syntax to ensure your credentials are
# encoded in the header. ####################################### curl --get "http://localhost:8086/query" \ --user "
exampleuser@influxdata.com
"
:"
INFLUX_API_TOKEN
"
\
--data-urlencode "db=mydb" \ --data-urlencode "q=SELECT * FROM cpu_usage"
/**
  * Use an InfluxDB Cloud username and token
  * with Basic Authentication
  * to query the InfluxDB 1.x compatibility API
  */

const https = require('https');
const querystring = require('querystring');

function queryWithUsername() {
  const queryparams = {
      db: 'mydb',
      q: 'SELECT * FROM cpu_usage',
  };

  const options = {
    host: 'localhost:8086',
    path: '/query?' + querystring.stringify(queryparams),
    auth: '
exampleuser@influxdata.com
:
INFLUX_API_TOKEN
'
,
headers: { 'Content-type': 'application/json' }, }; const request = https.get(options, (response) => { let rawData = ''; response.on('data', () => { response.on('data', (chunk) => { rawData += chunk; }); }) response.on('end', () => { console.log(rawData); }) }); request.end(); }

替换以下内容:

  • exampleuser@influxdata.com
    : 您注册时使用的电子邮件地址
  • INFLUX_API_TOKEN
    : 你的 InfluxDB API token

查询字符串认证

使用 InfluxDB 1.x API 参数通过查询字符串提供凭证。

使用查询字符串参数时需要考虑
  • 对可能包含空格或其他特殊字符的查询参数进行URL编码。
  • 在通过URL暴露敏感数据时要注意风险
语法
/query/?u=
INFLUX_USERNAME
&p=
INFLUX_API_TOKEN
/write/?u=
INFLUX_USERNAME
&p=
INFLUX_API_TOKEN
示例
#######################################
# Use an InfluxDB 1.x compatible username
# and password with Basic Authentication
# to query the InfluxDB 1.x compatibility API
#######################################
# Use default retention policy
#######################################
# Use the --user option with `--user 
INFLUX_USERNAME
:
INFLUX_API_TOKEN
` syntax
# or the `--user
INFLUX_USERNAME
` interactive syntax to ensure your credentials are
# encoded in the header. ####################################### curl --get "http://localhost:8086/query" \ --user "
exampleuser@influxdata.com
"
:"
INFLUX_API_TOKEN
"
\
--data-urlencode "db=mydb" \ --data-urlencode "q=SELECT * FROM cpu_usage"
/**
  * Use an InfluxDB Cloud username and token
  * with Basic Authentication
  * to query the InfluxDB 1.x compatibility API
  */

const https = require('https');
const querystring = require('querystring');

function queryWithUsername() {
  const queryparams = {
      db: 'mydb',
      q: 'SELECT * FROM cpu_usage',
  };

  const options = {
    host: 'localhost:8086',
    path: '/query?' + querystring.stringify(queryparams),
    auth: '
exampleuser@influxdata.com
:
INFLUX_API_TOKEN
'
,
headers: { 'Content-type': 'application/json' }, }; const request = https.get(options, (response) => { let rawData = ''; response.on('data', () => { response.on('data', (chunk) => { rawData += chunk; }); }) response.on('end', () => { console.log(rawData); }) }); request.end(); }

替换以下内容:

  • exampleuser@influxdata.com
    : 您注册时使用的电子邮件地址
  • INFLUX_API_TOKEN
    : 你的 InfluxDB API token
InfluxQL 支持

兼容性API支持InfluxQL,但有以下注意事项:

  • 不支持 INTO 子句(例如, SELECT ... INTO ...)。
  • 除了DELETEDROP MEASUREMENT查询仍然被允许,InfluxQL数据库管理命令不被支持。

兼容性端点



Flux的未来

Flux 正在进入维护模式。您可以像现在一样继续使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看:

由TSM驱动的InfluxDB Cloud