产品动态
公告
car,id=0,city=city_0,type=type_0 speed=100,temp=20 1675236656000000000car,id=1,city=city_1,type=type_1 speed=101,temp=21 1675236656000000000car,id=2,city=city_0,type=type_2 speed=102,temp=22 1675236656000000000car,id=3,city=city_1,type=type_0 speed=103,temp=23 1675236656000000000car,id=4,city=city_0,type=type_1 speed=104,temp=24 1675236656000000000car,id=5,city=city_1,type=type_2 speed=105,temp=25 1675236656000000000car,id=0,city=city_0,type=type_0 speed=106,temp=26 1675236657000000000car,id=1,city=city_1,type=type_1 speed=107,temp=27 1675236657000000000car,id=2,city=city_0,type=type_2 speed=108,temp=28 1675236657000000000car,id=3,city=city_1,type=type_0 speed=100,temp=29 1675236657000000000car,id=4,city=city_0,type=type_1 speed=101,temp=30 1675236657000000000car,id=5,city=city_1,type=type_2 speed=102,temp=20 1675236657000000000car,id=0,city=city_0,type=type_0 speed=103,temp=21 1675236658000000000car,id=1,city=city_1,type=type_1 speed=104,temp=22 1675236658000000000car,id=2,city=city_0,type=type_2 speed=105,temp=23 1675236658000000000car,id=3,city=city_1,type=type_0 speed=106,temp=24 1675236658000000000car,id=4,city=city_0,type=type_1 speed=107,temp=25 1675236658000000000car,id=5,city=city_1,type=type_2 speed=108,temp=26 1675236658000000000car,id=0,city=city_0,type=type_0 speed=100,temp=27 1675236659000000000car,id=1,city=city_1,type=type_1 speed=101,temp=28 1675236659000000000car,id=2,city=city_0,type=type_2 speed=102,temp=29 1675236659000000000car,id=3,city=city_1,type=type_0 speed=103,temp=30 1675236659000000000car,id=4,city=city_0,type=type_1 speed=104,temp=20 1675236659000000000car,id=5,city=city_1,type=type_2 speed=105,temp=21 1675236659000000000car,id=0,city=city_0,type=type_0 speed=106,temp=22 1675236660000000000car,id=1,city=city_1,type=type_1 speed=107,temp=23 1675236660000000000car,id=2,city=city_0,type=type_2 speed=108,temp=24 1675236660000000000car,id=3,city=city_1,type=type_0 speed=100,temp=25 1675236660000000000car,id=4,city=city_0,type=type_1 speed=101,temp=26 1675236660000000000car,id=5,city=city_1,type=type_2 speed=102,temp=27 1675236660000000000car,id=0,city=city_0,type=type_0 speed=103,temp=28 1675236661000000000car,id=1,city=city_1,type=type_1 speed=104,temp=29 1675236661000000000car,id=2,city=city_0,type=type_2 speed=105,temp=30 1675236661000000000car,id=3,city=city_1,type=type_0 speed=106,temp=20 1675236661000000000car,id=4,city=city_0,type=type_1 speed=107,temp=21 1675236661000000000car,id=5,city=city_1,type=type_2 speed=108,temp=22 1675236661000000000
CREATEDATABASE<database_name>[WITH[DURATION<duration[默认无限制]>]]
time_series_test_db,执行格式如下所示:curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode "pretty=true" \\--data-urlencode 'q=CREATE DATABASE time_series_test_db'
{"code": "invalid","message": "Tsdb create database operation is executing, please try again later(maybe failture)."}
{"results": [{"statement_id": 0}]}
show database,查看已经创建的数据库,执行格式如下所示:curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode "pretty=true" \\--data-urlencode 'q=show databases'
[root@VM-16-41-centos ~]# curl --get http://10.16.12.8:8086/query \\> --user "ctsdbi-8ym3****":"test@123" \\> --data-urlencode "pretty=true" \\> --data-urlencode 'q=show databases'{"results": [{"statement_id": 0,"series": [{"name": "databases","columns": ["name"],"columns_types": ["string"],"values": [["test0407"],["time_series_test_db"],["_internal"],["TestAlvinDatabase"],["time_series_test_db0"]]}]}]}
curl -v --data-binary @/tmp/line_protocol_sample.txt \\--user "time_series_test_account":"test_password" \\-H "Content-Type: text/plain" \\-H "Accept: application/json" -X POST \\"http://${influxdb_ip}:8086/write?db=time_series_test_db&precision=ns"
/tmp/test.txt文档中的时序数据写入数据库time_series_test_db。[root@VM-16-41-centos tmp]# curl -v --data-binary @/tmp/test.txt \\> --user "ctsdbi-8ym3****":"test@123" \\> -H "Content-Type: text/plain" \\> -H "Accept: application/json" -X POST \\> "http://10.16.12.8:8086/write?db=time_series_test_db&precision=ns"* About to connect() to 10.16.12.8 port 8086 (#0)* Trying 10.16.12.8...* Connected to 10.16.12.8 (10.16.12.8) port 8086 (#0)* Server auth using Basic with user 'ctsdbi-8ym3****'> POST /write?db=time_series_test_db&precision=ns HTTP/1.1> Authorization: Basic Y3RzZGJpLTh5********************> User-Agent: curl/7.29.0> Host: 10.16.12.8:8086> Content-Type: text/plain> Accept: application/json> Content-Length: 2552> Expect: 100-continue>* Done waiting for 100-continue< HTTP/1.1 204 No Content< Date: Mon, 10 Apr 2023 03:48:51 GMT< Content-Type: application/json< Content-Length: 0<* Connection #0 to host 10.16.12.8 left intact
Date: Mon, 10 Apr 2023 03:48:51 GMT显示写入完成的时间点,无任何错误提示信息,说明写入成功。常见的错误信息,请参见下表。错误信息 | 错误含义 | 处理方式 |
{
"error": "NotFoundCollection cannot find collections"
}
| 连接失败 | 排查连接数据库的内网 IP 地址与端口是否正确。 |
{
"error": "BadParam ERR wrong password.\\r\\n"
} | 访问数据库的账户密码错误 | 请检查密码信息是否正确。 |
{
"error": "NotFoundAccount ERR account id or name not exists: 1nB3pmg=="
} | 访问数据的账户不存在 | 请检查账户信息是否输入错误。 |
{
"error": "InvalidFieldFormat ParsePoint() failed|status=InvalidFieldFormat InvalidBooleanFormat not start with tTfF|line=727|col=14\\ncar id=0,city=city_0,type=type_0 speed=100,temp=20 0\\n | start here"
} | 数据写入失败 | 请检查 car id=0,city=city_0,type=type_0 speed=100,temp=20这一行数据的第14个字符是否存在 Line Protocol 格式问题。 |
show measurements 查看写入的 measurements,执行方式如下所示:curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode "q=show measurements"
[root@VM-16-41-centos ~]# curl --get http://10.16.12.8:8086/query \\> --user "ctsdbi-8ym3****":"test@123" \\> --data-urlencode 'db=time_series_test_db' \\> --data-urlencode "pretty=true" \\> --data-urlencode "q=show measurements"{"results": [{"statement_id": 0,"series": [{"name": "measurements","columns": ["name"],"columns_types": ["string"],"values": [["car"],["d=0"]]}]}]}
select_stmt = "SELECT" fields from_clause [ where_clause ] [ group_by_clause ] [ order_by_clause ] [ limit_clause ] [ offset_clause ] [ slimit_clause ] [ soffset_clause ] [ sql_order_by_clause ]
参数 | 参数含义 |
fields | 指定需要查询的字段列表,可以是一个或多个字段,用逗号分隔。如果需要查询所有字段,可以使用通配符“*”。 |
from_clause | 指定需要查询的 measurement 名称。 |
where_clause | 指定查询的条件,可以是一个或多个条件,可以使用 AND、OR、NOT 等逻辑运算符组合多个条件。条件包括 tag 和 field,可以使用比较运算符(如=、!=、>、<等)进行比较。 |
group_by_clause | 指定查询结果需要按照哪个 tag 进行分组,可以是一个或多个 tag,用逗号分隔。 |
order_by_clause | 指定查询结果需要按照哪个字段进行排序,可以是一个或多个字段,用逗号分隔。默认情况下,查询结果按照时间戳排序。 |
limit_clause | 指定查询结果的最大行数。 |
offset_clause | 指定查询结果的起始行数。 |
slimit_clause | 类似于 limit_clause,但仅应用于每个分组内部的结果集。 |
soffset_clause | 类似于 offset_clause,但仅应用于每个分组内部的结果集。 |
sql_order_by_clause | 类似于 order_by_clause,但是使用 SQL 语法进行排序。 |
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode 'q=select * from car'
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode 'q=select * from car limit 3 offset 2'
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode 'q=select max(speed) as fun1, min(speed) as fun2 from car group by time(3s), type fill(none)'
{"results": [{"statement_id": 0,"series": [{"name": "car","tags": {"type": "type_0"},"columns": ["time","fun1","fun2"],"columns_types": ["time","float","float"],"values": [["2023-02-01T07:30:54Z",103.0,100.0],["2023-02-01T07:30:57Z",106.0,100.0],["2023-02-01T07:31:00Z",106.0,100.0]]},{"name": "car","tags": {"type": "type_1"},"columns": ["time","fun1","fun2"],"columns_types": ["time","float","float"],"values": [["2023-02-01T07:30:54Z",104.0,101.0],["2023-02-01T07:30:57Z",107.0,101.0],["2023-02-01T07:31:00Z",107.0,101.0]]},{"name": "car","tags": {"type": "type_2"},"columns": ["time","fun1","fun2"],"columns_types": ["time","float","float"],"values": [["2023-02-01T07:30:54Z",105.0,102.0],["2023-02-01T07:30:57Z",108.0,102.0],["2023-02-01T07:31:00Z",108.0,102.0]]}]}]}
DELETE FROM<measurement_name>WHERE [<tag_key>='<tag_value>'] | [<time interval>]
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode "q=delete from car where city = 'city_0'"
DROP MEASUREMENT<measurement_name>
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode 'db=time_series_test_db' \\--data-urlencode "pretty=true" \\--data-urlencode 'q=dropmeasurementcar'
DROP DATABASE<database_name>
curl --get http://${influxdb_ip}:8086/query \\--user "time_series_test_account":"test_password" \\--data-urlencode "pretty=true" \\--data-urlencode 'q=DROP DATABASEtime_series_test_db'
{"results": [{"statement_id": 0}]}
文档反馈