influxdb.api() 函数
influxdb.api()
处于实验阶段,并且随时可能更改。
influxdb.api()
向指定的 InfluxDB API 路径提交 HTTP 请求,并返回包含 HTTP 状态代码、响应标头和响应正文的记录。
注意:influxdb.api()
使用指定 token
的授权,或者,如果从 InfluxDB UI 执行,则使用调用脚本的 InfluxDB 用户的授权。授权权限和限制适用于每个请求。
响应格式
influxdb.api()
返回包含以下属性的记录
- statusCode:GET 请求返回的 HTTP 状态代码(int)。
- headers:HTTP 响应标头(dict)。
- body:HTTP 响应正文(bytes)。
函数类型签名
(
method: string,
path: string,
?body: bytes,
?headers: [string:string],
?host: string,
?query: [string:string],
?timeout: duration,
?token: string,
) => {statusCode: int, headers: [string:string], body: bytes}
有关更多信息,请参阅函数类型签名。
参数
method
(必需)HTTP 请求方法。
path
(必需)InfluxDB API 路径。
host
InfluxDB 主机 URL(在 InfluxDB 外部执行时为必需)。默认为 ""
。
token
InfluxDB API 令牌(在 InfluxDB 外部执行时为必需)。默认为 ""
。
headers
HTTP 请求标头。
query
URL 查询参数。
timeout
HTTP 请求超时。默认为 30s
。
body
HTTP 请求正文,以字节为单位。
示例
检索 InfluxDB OSS 实例的运行状况
import "experimental/influxdb"
import "influxdata/influxdb/secrets"
token = secrets.get(key: "INFLUX_TOKEN")
response = influxdb.api(method: "get", path: "/health", host: "http://localhost:8086", token: token)
string(v: response.body)
通过 InfluxDB Cloud API 创建存储桶
import "experimental/influxdb"
import "json"
import "influxdata/influxdb/secrets"
token = secrets.get(key: "INFLUX_TOKEN")
influxdb.api(
method: "post",
path: "/api/v2/buckets",
host: "https://us-west-2-1.aws.cloud2.influxdata.com",
token: token,
body:
json.encode(
v: {
name: "example-bucket",
description: "This is an example bucket.",
orgID: "x000X0x0xx0X00x0",
retentionRules: [],
},
),
)
此页面是否对您有帮助?
感谢您的反馈!