InfluxDB 3 Core 的 InfluxDB HTTP API 为与 InfluxDB 3 Core 数据库和资源交互提供了程序化接口。使用此 API 可以
API 包括以下路径下的端点
/api/v3
: InfluxDB 3 Core 原生端点/
: InfluxDB v1 工作负载和客户端的兼容性端点/api/v2/write
: InfluxDB v2 工作负载和客户端的兼容性端点curl "http://localhost:8181/health"
将数据写入 InfluxDB。
curl "http://localhost:8181/api/v3/write_lp?db=sensors&precision=auto" \
--data-raw "home,room=Kitchen temp=72.0
home,room=Living\ room temp=71.5"
如果所有数据都已写入,则响应为 204 No Content
。
curl -G "http://localhost:8181/api/v3/query_sql" \
--data-urlencode "db=sensors" \
--data-urlencode "q=SELECT * FROM home WHERE room='Living room'" \
--data-urlencode "format=jsonl"
输出
{"room":"Living room","temp":71.5,"time":"2025-02-25T20:19:34.984098"}
有关使用 InfluxDB 3 Core 的更多信息,请参阅入门指南。
InfluxDB 3 为 InfluxDB 1.x 和 InfluxDB 2.x 工作负载和客户端提供兼容性端点。
/api/v2/write
端点,适用于 InfluxDB v2 客户端以及您将现有 InfluxDB v2 写入工作负载迁移到 InfluxDB 3 时。/write
端点,适用于 InfluxDB v1 客户端以及您将现有 InfluxDB v1 写入工作负载迁移到 InfluxDB 3 时。对于新的工作负载,请使用 /api/v3/write_lp
端点。
所有端点都接受相同的行协议格式。
对于 InfluxDB v1 客户端和使用 InfluxQL 的 v1 查询工作负载,请使用 HTTP /query
端点。
对于新的工作负载,请使用以下端点之一
/api/v3/query_sql
端点,适用于使用 SQL 的新查询工作负载。/api/v3/query_influxql
端点,适用于使用 InfluxQL 的新查询工作负载。服务器信息端点(如 /health
和 metrics
)与 InfluxDB 1.x 和 InfluxDB 2.x 客户端兼容。
将行协议写入到指定的数据库。
此端点为使用 InfluxDB 1.x 客户端库、Telegraf outputs.influxdb
输出插件或第三方工具等工具的 InfluxDB 1.x 写入工作负载提供向后兼容性。
使用此端点以 行协议 格式将数据发送到 InfluxDB。使用查询参数指定写入数据的选项。
db 必需 | string 数据库的名称。数据库的名称。如果数据库尚不存在,InfluxDB 将创建数据库,然后将批处理中的所有点写入到该数据库。 |
precision 必需 | string (PrecisionWriteCompatibility) 枚举: "ms" "s" "us" "ns" 行协议批处理中 Unix 时间戳的精度。 |
Accept | string 默认值: application/json 值: "application/json" 客户端可以理解的内容类型。仅当写入失败(部分或完全失败)时,写入才会返回响应正文,例如,由于语法问题或类型不匹配。 |
Content-Encoding | string (ContentEncoding) 默认值: identity 枚举: "gzip" "identity" 应用于请求负载中行协议的压缩。要发送 gzip 负载,请传递 |
Content-Length | integer (ContentLength) 发送到 InfluxDB 的实体主体的大小,以字节为单位。 |
Content-Type | string (LineProtocol) 默认值: text/plain; charset=utf-8 枚举: "text/plain" "text/plain; charset=utf-8" 请求负载的内容类型。 |
measurement,tag=value field=1 1234567890
"{\n \"error\": \"行协议写入失败\",\n \"data\": [\n {\n \"original_line\": \"dquote> home,room=Kitchen temp=hi\",\n \"line_number\": 2,\n \"error_message\": \"未提供任何字段\"\n }\n ]\n}\n"
将行协议写入到指定的数据库。
此端点为使用 InfluxDB 2.x 客户端库、Telegraf outputs.influxdb_v2
输出插件或第三方工具等工具的 InfluxDB 2.x 写入工作负载提供向后兼容性。
使用此端点以 行协议 格式将数据发送到 InfluxDB。使用查询参数指定写入数据的选项。
accept_partial | boolean (AcceptPartial) 默认值: true 接受部分写入。 |
db 必需 | string 数据库名称。如果数据库尚不存在,InfluxDB 将创建数据库,然后将批处理中的所有点写入到该数据库。 |
precision 必需 | string (PrecisionWriteCompatibility) 枚举: "ms" "s" "us" "ns" 行协议批处理中 Unix 时间戳的精度。 |
Accept | string 默认值: application/json 值: "application/json" 客户端可以理解的内容类型。仅当写入失败(部分或完全失败)时,写入才会返回响应正文,例如,由于语法问题或类型不匹配。 |
Content-Encoding | string 默认值: identity 枚举: "gzip" "identity" 应用于请求负载中行协议的压缩。要发送 gzip 负载,请传递 |
Content-Length | integer 发送到 InfluxDB 的实体主体的大小,以字节为单位。 |
Content-Type | string (LineProtocol) 默认值: text/plain; charset=utf-8 枚举: "text/plain" "text/plain; charset=utf-8" 请求负载的内容类型。 |
measurement,tag=value field=1 1234567890
{- "error": "string",
- "data": { }
}
执行 InfluxQL 查询以从指定的数据库检索数据。
此端点与 InfluxDB 1.x 客户端库和第三方集成(如 Grafana)兼容。使用查询参数指定数据库和 InfluxQL 查询。
chunk_size | integer 默认值: 10000 将进入一个块的记录数。仅当 |
chunked | boolean 默认值: false 如果为 true,则响应将分为大小为 |
db | string <InfluxQL> 要查询的数据库。如果未提供,则 InfluxQL 查询字符串必须指定数据库。 |
epoch | string (EpochCompatibility) 枚举: "ns" "u" "µ" "ms" "s" "m" "h" 将时间戳格式化为具有指定精度的 unix(纪元)时间戳,而不是具有纳秒精度的 RFC3339 时间戳。 |
pretty | boolean 默认值: false 如果为 true,则 JSON 响应将以人类可读的格式格式化。 |
q 必需 | string InfluxQL 查询字符串。 |
Accept | string 默认值: application/json 枚举: "application/json" "application/csv" "text/csv" 客户端可以理解的内容类型。 如果指定 如果格式无效或非 UTF8,则返回错误。 |
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 InfluxQL 查询以从指定的数据库检索数据。
Accept | string 默认值: application/json 枚举: "application/json" "application/csv" "text/csv" 客户端可以理解的内容类型。 如果指定 如果格式无效或非 UTF8,则返回错误。 |
chunk_size | integer 默认值: 10000 将进入一个块的记录数。仅当 |
chunked | boolean 如果为 true,则响应将分为大小为 |
db | string 要查询的数据库。如果未提供,则 InfluxQL 查询字符串必须指定数据库。 |
epoch | string 枚举: "ns" "u" "µ" "ms" "s" "m" "h" Unix 时间戳精度。
将时间戳格式化为具有指定精度的 unix(纪元)时间戳,而不是具有纳秒精度的 RFC3339 时间戳。 |
pretty | boolean 如果为 true,则 JSON 响应将以人类可读的格式格式化。 |
q 必需 | string InfluxQL 查询字符串。 |
{- "db": "string",
- "q": "string",
- "chunked": true,
- "chunk_size": 10000,
- "epoch": "ns",
- "pretty": true
}
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
写入和查询数据
no_sync
写入选项 (no_sync=true
),服务器将发送响应以确认写入。no_sync=false
(默认),服务器将发送响应以确认写入。将行协议写入到指定的数据库。
此端点为使用 InfluxDB 1.x 客户端库、Telegraf outputs.influxdb
输出插件或第三方工具等工具的 InfluxDB 1.x 写入工作负载提供向后兼容性。
使用此端点以 行协议 格式将数据发送到 InfluxDB。使用查询参数指定写入数据的选项。
db 必需 | string 数据库的名称。数据库的名称。如果数据库尚不存在,InfluxDB 将创建数据库,然后将批处理中的所有点写入到该数据库。 |
precision 必需 | string (PrecisionWriteCompatibility) 枚举: "ms" "s" "us" "ns" 行协议批处理中 Unix 时间戳的精度。 |
Accept | string 默认值: application/json 值: "application/json" 客户端可以理解的内容类型。仅当写入失败(部分或完全失败)时,写入才会返回响应正文,例如,由于语法问题或类型不匹配。 |
Content-Encoding | string (ContentEncoding) 默认值: identity 枚举: "gzip" "identity" 应用于请求负载中行协议的压缩。要发送 gzip 负载,请传递 |
Content-Length | integer (ContentLength) 发送到 InfluxDB 的实体主体的大小,以字节为单位。 |
Content-Type | string (LineProtocol) 默认值: text/plain; charset=utf-8 枚举: "text/plain" "text/plain; charset=utf-8" 请求负载的内容类型。 |
measurement,tag=value field=1 1234567890
"{\n \"error\": \"行协议写入失败\",\n \"data\": [\n {\n \"original_line\": \"dquote> home,room=Kitchen temp=hi\",\n \"line_number\": 2,\n \"error_message\": \"未提供任何字段\"\n }\n ]\n}\n"
将行协议写入到指定的数据库。
此端点为使用 InfluxDB 2.x 客户端库、Telegraf outputs.influxdb_v2
输出插件或第三方工具等工具的 InfluxDB 2.x 写入工作负载提供向后兼容性。
使用此端点以 行协议 格式将数据发送到 InfluxDB。使用查询参数指定写入数据的选项。
accept_partial | boolean (AcceptPartial) 默认值: true 接受部分写入。 |
db 必需 | string 数据库名称。如果数据库尚不存在,InfluxDB 将创建数据库,然后将批处理中的所有点写入到该数据库。 |
precision 必需 | string (PrecisionWriteCompatibility) 枚举: "ms" "s" "us" "ns" 行协议批处理中 Unix 时间戳的精度。 |
Accept | string 默认值: application/json 值: "application/json" 客户端可以理解的内容类型。仅当写入失败(部分或完全失败)时,写入才会返回响应正文,例如,由于语法问题或类型不匹配。 |
Content-Encoding | string 默认值: identity 枚举: "gzip" "identity" 应用于请求负载中行协议的压缩。要发送 gzip 负载,请传递 |
Content-Length | integer 发送到 InfluxDB 的实体主体的大小,以字节为单位。 |
Content-Type | string (LineProtocol) 默认值: text/plain; charset=utf-8 枚举: "text/plain" "text/plain; charset=utf-8" 请求负载的内容类型。 |
measurement,tag=value field=1 1234567890
{- "error": "string",
- "data": { }
}
将行协议写入到指定的数据库。
使用此端点以 行协议 格式将数据发送到 InfluxDB。使用查询参数指定写入数据的选项。
accept_partial | boolean (AcceptPartial) 默认值: true 接受部分写入。 |
db 必需 | string 数据库的名称。数据库的名称。如果数据库尚不存在,InfluxDB 将创建数据库,然后将批处理中的所有点写入到该数据库。 |
no_sync | boolean (NoSync) 默认值: false 确认成功写入,无需等待 WAL 持久化。 InfluxDB 3 Core 中的数据流
|
precision 必需 | string (PrecisionWrite) 枚举: "auto" "millisecond" "second" "microsecond" "nanosecond" 时间戳精度。 |
Accept | string 默认值: application/json 值: "application/json" 客户端可以理解的内容类型。仅当写入失败(部分或完全失败)时,写入才会返回响应正文,例如,由于语法问题或类型不匹配。 |
Content-Encoding | string (ContentEncoding) 默认值: identity 枚举: "gzip" "identity" 应用于请求负载中行协议的压缩。要发送 gzip 负载,请传递 |
Content-Length | integer (ContentLength) 发送到 InfluxDB 的实体主体的大小,以字节为单位。 |
Content-Type | string (LineProtocol) 默认值: text/plain; charset=utf-8 枚举: "text/plain" "text/plain; charset=utf-8" 请求负载的内容类型。 |
measurement,tag=value field=1 1234567890
{- "error": "string",
- "data": { }
}
执行 SQL 查询以从指定的数据库检索数据。
db 必需 | string 数据库的名称。 |
format | string |
q 必需 | string |
Accept | string 默认值: application/json 枚举: "application/json" "application/jsonl" "application/vnd.apache.parquet" "text/csv" 客户端可以理解的内容类型。 |
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 SQL 查询以从指定的数据库检索数据。
Accept | string 默认值: application/json 枚举: "application/json" "application/jsonl" "application/vnd.apache.parquet" "text/csv" 客户端可以理解的内容类型。 |
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
database 必需 | string 要查询的数据库的名称。如果查询 ( |
format | string 枚举: "json" "csv" "parquet" "jsonl" "pretty" 查询结果的格式。 |
object 查询的附加参数。使用此字段传递查询参数。 | |
query_str 必需 | string 要执行的查询。 |
{- "database": "mydb",
- "query_str": "SELECT * FROM mytable",
- "format": "json",
- "params": { }
}
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 InfluxQL 查询以从指定的数据库检索数据。
db | string 数据库的名称。 如果您提供的查询指定了数据库,则可以从请求中省略 'db' 参数。 |
format | string |
q 必需 | string |
Accept | string 默认值: application/json 枚举: "application/json" "application/jsonl" "application/vnd.apache.parquet" "text/csv" 客户端可以理解的内容类型。 |
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 InfluxQL 查询以从指定的数据库检索数据。
Accept | string 默认值: application/json 枚举: "application/json" "application/jsonl" "application/vnd.apache.parquet" "text/csv" 客户端可以理解的内容类型。 |
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
database 必需 | string 要查询的数据库的名称。如果查询 ( |
format | string 枚举: "json" "csv" "parquet" "jsonl" "pretty" 查询结果的格式。 |
object 查询的附加参数。使用此字段传递查询参数。 | |
query_str 必需 | string 要执行的查询。 |
{- "database": "mydb",
- "query_str": "SELECT * FROM mytable",
- "format": "json",
- "params": { }
}
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 InfluxQL 查询以从指定的数据库检索数据。
此端点与 InfluxDB 1.x 客户端库和第三方集成(如 Grafana)兼容。使用查询参数指定数据库和 InfluxQL 查询。
chunk_size | integer 默认值: 10000 将进入一个块的记录数。仅当 |
chunked | boolean 默认值: false 如果为 true,则响应将分为大小为 |
db | string <InfluxQL> 要查询的数据库。如果未提供,则 InfluxQL 查询字符串必须指定数据库。 |
epoch | string (EpochCompatibility) 枚举: "ns" "u" "µ" "ms" "s" "m" "h" 将时间戳格式化为具有指定精度的 unix(纪元)时间戳,而不是具有纳秒精度的 RFC3339 时间戳。 |
pretty | boolean 默认值: false 如果为 true,则 JSON 响应将以人类可读的格式格式化。 |
q 必需 | string InfluxQL 查询字符串。 |
Accept | string 默认值: application/json 枚举: "application/json" "application/csv" "text/csv" 客户端可以理解的内容类型。 如果指定 如果格式无效或非 UTF8,则返回错误。 |
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
执行 InfluxQL 查询以从指定的数据库检索数据。
Accept | string 默认值: application/json 枚举: "application/json" "application/csv" "text/csv" 客户端可以理解的内容类型。 如果指定 如果格式无效或非 UTF8,则返回错误。 |
chunk_size | integer 默认值: 10000 将进入一个块的记录数。仅当 |
chunked | boolean 如果为 true,则响应将分为大小为 |
db | string 要查询的数据库。如果未提供,则 InfluxQL 查询字符串必须指定数据库。 |
epoch | string 枚举: "ns" "u" "µ" "ms" "s" "m" "h" Unix 时间戳精度。
将时间戳格式化为具有指定精度的 unix(纪元)时间戳,而不是具有纳秒精度的 RFC3339 时间戳。 |
pretty | boolean 如果为 true,则 JSON 响应将以人类可读的格式格式化。 |
q 必需 | string InfluxQL 查询字符串。 |
{- "db": "string",
- "q": "string",
- "chunked": true,
- "chunk_size": 10000,
- "epoch": "ns",
- "pretty": true
}
{- "results": [
- {
- "series": [
- {
- "name": "mytable",
- "columns": [
- "time",
- "value"
], - "values": [
- [
- "2024-02-02T12:00:00Z",
- 42
]
]
}
]
}
]
}
{- "db": "string"
}
{- "error": "string",
- "data": { }
}
{- "error": "string",
- "data": { }
}
管理处理引擎触发器、测试插件以及发送请求以触发“按需”插件。
InfluxDB 3 Core 提供 InfluxDB 3 处理引擎,这是一个嵌入式 Python VM,可以动态加载和触发 Python 插件以响应数据库中的事件。使用处理引擎插件和触发器来运行代码并执行不同数据库事件的任务。
要开始使用处理引擎,请参阅处理引擎和 Python 插件指南。
创建新的处理引擎触发器。
db 必需 | string |
disabled | boolean |
plugin_filename 必需 | string |
object | |
trigger_name 必需 | string |
trigger_specification 必需 | string |
{- "db": "string",
- "plugin_filename": "string",
- "trigger_name": "string",
- "trigger_specification": "string",
- "trigger_arguments": { },
- "disabled": true
}
{- "error": "string",
- "data": { }
}
{- "error": "string",
- "data": { }
}
禁用处理引擎触发器。
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
db 必需 | string |
disabled | boolean |
plugin_filename 必需 | string |
object | |
trigger_name 必需 | string |
trigger_specification 必需 | string |
{- "db": "string",
- "plugin_filename": "string",
- "trigger_name": "string",
- "trigger_specification": "string",
- "trigger_arguments": { },
- "disabled": true
}
{- "error": "string",
- "data": { }
}
启用处理引擎触发器。
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
db 必需 | string |
disabled | boolean |
plugin_filename 必需 | string |
object | |
trigger_name 必需 | string |
trigger_specification 必需 | string |
{- "db": "string",
- "plugin_filename": "string",
- "trigger_name": "string",
- "trigger_specification": "string",
- "trigger_arguments": { },
- "disabled": true
}
{- "error": "string",
- "data": { }
}
{- "error": "string",
- "data": { }
}
{- "error": "string",
- "data": { }
}
发送请求以调用按需处理引擎插件。请求可以包含请求标头、查询字符串参数和请求正文,InfluxDB 将其传递给插件。
按需插件实现以下签名
def process_request(influxdb3_local, query_parameters, request_headers, request_body, args=None)
响应取决于插件实现。
plugin_path 必需 | string 在插件的 例如,如果您使用以下内容定义触发器
然后,HTTP API 公开以下插件端点
|
{- "error": "string",
- "data": { }
}
发送请求以调用按需处理引擎插件。请求可以包含请求标头、查询字符串参数和请求正文,InfluxDB 将其传递给插件。
按需插件实现以下签名
def process_request(influxdb3_local, query_parameters, request_headers, request_body, args=None)
响应取决于插件实现。
plugin_path 必需 | string 在插件的 例如,如果您使用以下内容定义触发器
然后,HTTP API 公开以下插件端点
|
Content-Type | string 值: "application/json" 请求主体中数据的格式。 |
属性名称* | any |
{ }
{- "error": "string",
- "data": { }
}
{- "version": "0.1.0",
- "revision": "f3d3d3d"
}
{- "error": "string",
- "data": { }
}
为表格创建最后缓存。
count | integer 可选的计数。 |
db 必需 | string |
key_columns | Array of strings 可选的键列列表。 |
name | string 可选的缓存名称。 |
table 必需 | string |
ttl | integer 可选的生存时间(秒)。 |
value_columns | Array of strings 可选的值列列表。 |
{- "db": "mydb",
- "table": "mytable",
- "key_columns": [
- "tag1"
], - "value_columns": [
- "field1"
], - "count": 100,
- "ttl": 3600
}
{- "error": "string",
- "data": { }
}
{- "error": "string",
- "data": { }
}