文档文档

InfluxDB 1.x 兼容性 API

InfluxDB v2 API 包括 InfluxDB 1.x 兼容性端点,这些端点可与 InfluxDB 1.x 客户端库和第三方集成(如 Grafana 等)一起使用。

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

身份验证

InfluxDB 1.x 兼容性端点要求所有查询和写入请求都使用 API 令牌或 1.x 兼容的凭据进行身份验证。

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

令牌身份验证需要以下凭据

使用带有 Token 方案的 Authorization 标头向 InfluxDB 提供您的令牌。Token 方案是单词 Token、一个空格和您的令牌(所有内容区分大小写)。

语法

Authorization: Token INFLUX_API_TOKEN
  • Copy
  • Fill window

示例

#######################################
# 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 "https://127.0.0.1:8086" \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --header 'Content-type: application/json' \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM cpu_usage"
  • Copy
  • Fill window
/**
  * 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();
}
  • Copy
  • Fill window

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

将以下身份验证方案与支持 InfluxDB 1.x 约定 usernamepassword 的客户端(不支持 Authorization: Token 方案的客户端)一起使用

管理凭据

用户名和密码方案需要以下凭据

  • username:1.x 用户名(这与 UI 登录用户名不同)
  • password:1.x 密码或 InfluxDB API 令牌。

密码或令牌

如果您为 1.x 兼容的用户名设置了密码,请提供 1.x 兼容的密码。如果您没有为 1.x 兼容的用户名设置密码,请提供 InfluxDB 身份验证令牌作为密码。

有关更多信息,请参阅如何在从 InfluxDB v1 手动升级到 v2 时创建和管理 1.x 兼容的授权

基本身份验证

使用带有 Basic 方案的 Authorization 标头向 InfluxDB 提供用户名和密码凭据。

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

语法
Authorization: Basic INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN
  • Copy
  • Fill window
示例
#######################################
# Use Basic authentication with an
# InfluxDB 1.x compatible username and password
# to query the InfluxDB 1.x compatibility API.
#
# Replace 
INFLUX_USERNAME
with your 1.x-compatible username.
# Replace
INFLUX_PASSWORD_OR_TOKEN
with your InfluxDB API token
# or 1.x-compatible password. ####################################### # Use the default retention policy. ####################################### # Use the --user option with `--user <username>:<password>` syntax # or the `--user <username>` interactive syntax to ensure your credentials are # encoded in the header. ####################################### curl --get "https://127.0.0.1:8086/query" \ --user "
INFLUX_USERNAME
"
:"
INFLUX_PASSWORD_OR_TOKEN
"
\
--data-urlencode "db=mydb" \ --data-urlencode "q=SELECT * FROM cpu_usage"
  • Copy
  • Fill window
/**
  * Use Basic authentication with an
  * InfluxDB 1.x compatible username and password
  * to query the InfluxDB 1.x compatibility API.

  * Replace 
INFLUX_USERNAME
with your 1.x-compatible username.
* Replace
INFLUX_PASSWORD_OR_TOKEN
with your InfluxDB API token
* or 1.x-compatible password. * Use the default retention policy. */ 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: '
INFLUX_USERNAME
:
INFLUX_PASSWORD_OR_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(); }
  • Copy
  • Fill window

查询字符串身份验证

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

使用查询字符串参数时的注意事项
  • URL 编码可能包含空格或其他特殊字符的查询参数。
  • 请注意通过 URL 公开敏感数据时的风险
语法
 /query/?u=
INFLUX_USERNAME
&p=
INFLUX_PASSWORD_OR_TOKEN
/write/?u=
INFLUX_USERNAME
&p=
INFLUX_PASSWORD_OR_TOKEN
  • Copy
  • Fill window
示例
#######################################
# Use querystring authentication with an
# InfluxDB 1.x compatible username and password
# to query the InfluxDB 1.x compatibility API.
#
# Replace 
INFLUX_USERNAME
with your 1.x-compatible username.
# Replace
INFLUX_PASSWORD_OR_TOKEN
with your InfluxDB API token
# or 1.x-compatible password. # # Use the default retention policy. ####################################### curl --get "https://127.0.0.1:8086/query" \ --data-urlencode "u=
INFLUX_USERNAME
"
\
--data-urlencode "p=
INFLUX_PASSWORD_OR_TOKEN
"
\
--data-urlencode "db=mydb" \ --data-urlencode "q=SELECT * FROM cpu_usage"
  • Copy
  • Fill window
/**
  * Use querystring authentication with an
  * InfluxDB 1.x compatible username and password
  * to query the InfluxDB 1.x compatibility API.
  *
  * Replace 
INFLUX_USERNAME
with your 1.x-compatible username.
* Replace
INFLUX_PASSWORD_OR_TOKEN
with your InfluxDB API token
* or 1.x-compatible password. * * Use the default retention policy. */ const https = require('https'); const querystring = require('querystring'); function queryWithToken() { const queryparams = { db: 'mydb', q: 'SELECT * FROM cpu_usage', u: '
INFLUX_USERNAME
'
,
p: '
INFLUX_PASSWORD_OR_TOKEN
'
}; const options = { host: 'localhost:8086', path: "/query?" + querystring.stringify(queryparams) }; 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(); }
  • Copy
  • Fill window

替换以下内容

替换以下内容

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

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

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

兼容性端点


此页内容是否对您有帮助?

感谢您的反馈!


Flux 的未来

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

阅读更多

InfluxDB 3 开源版本现已公开发布 Alpha 版

InfluxDB 3 开源版本现已可用于 Alpha 测试,根据 MIT 或 Apache 2 许可获得许可。

我们正在发布两个产品作为 Alpha 版本的一部分。

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

有关如何入门的更多信息,请查看