InfluxDB Line Protocol
GreptimeDB 支持 HTTP InfluxDB Line 协议。
写入新数据
协议
Post 指标
你可以通过 /influxdb/write API 写入数据。
以下是一个示例:
- InfluxDB line protocol V2
- InfluxDB line protocol V1
curl -i -XPOST "http://localhost:4000/v1/influxdb/api/v2/write?db=public&precision=ms" \
-H "authorization: token {{greptime_user:greptimedb_password}}" \
--data-binary \
'monitor,host=127.0.0.1 cpu=0.1,memory=0.4 1667446797450
monitor,host=127.0.0.2 cpu=0.2,memory=0.3 1667446798450
monitor,host=127.0.0.1 cpu=0.5,memory=0.2 1667446798450'
curl -i -XPOST "http://localhost:4000/v1/influxdb/write?db=public&precision=ms&u=<greptime_user>&p=<greptimedb_password>" \
--data-binary \
'monitor,host=127.0.0.1 cpu=0.1,memory=0.4 1667446797450
monitor,host=127.0.0.2 cpu=0.2,memory=0.3 1667446798450
monitor,host=127.0.0.1 cpu=0.5,memory=0.2 1667446798450'
/influxdb/write 支持查询参数,包括:
db:指定要写入的数据库。默认值为public。precision:定义请求体中提供的时间戳的精度,可接受的值为ns(纳秒)、us(微秒)、ms(毫秒)和s(秒),默认值为ns(纳秒)。该 API 写入的时间戳类型为TimestampNanosecond,因此默认精度为ns(纳秒)。如果你在请求体中使用了其他精度的的时间戳,需要使用此参数指定精度。该参数确保时间戳能够被准确解释并以纳秒精度存储。
你还可以在发送请求时省略 timestamp,GreptimeDB 将使用主机机 器的当前系统时间(UTC 时间)作为 timestamp。例如:
- InfluxDB line protocol V2
- InfluxDB line protocol V1
curl -i -XPOST "http://localhost:4000/v1/influxdb/api/v2/write?db=public" \
-H "authorization: token {{greptime_user:greptimedb_password}}" \
--data-binary \
'monitor,host=127.0.0.1 cpu=0.1,memory=0.4
monitor,host=127.0.0.2 cpu=0.2,memory=0.3
monitor,host=127.0.0.1 cpu=0.5,memory=0.2'
curl -i -XPOST "http://localhost:4000/v1/influxdb/write?db=public&u=<greptime_user>&p=<greptimedb_password>" \
--data-binary \
'monitor,host=127.0.0.1 cpu=0.1,memory=0.4
monitor,host=127.0.0.2 cpu=0.2,memory=0.3
monitor,host=127.0.0.1 cpu=0.5,memory=0.2'
鉴权
GreptimeDB 与 InfluxDB 的行协议鉴权格式兼容,包括 V1 和 V2。 如果你在 GreptimeDB 中配置了鉴权,需要在 HTTP 请求中提供用户名和密码。
- InfluxDB line protocol V2
- InfluxDB line protocol V1
InfluxDB 的 V2 协议 使用了类似 HTTP 标准 basic 认证方案的格式。
curl 'http://localhost:4000/v1/influxdb/api/v2/write?db=public' \
-H 'authorization: token {{username:password}}' \
-d 'monitor,host=127.0.0.1 cpu=0.1,memory=0.4'