InfluxDB Line Protocol
GreptimeDB supports HTTP InfluxDB Line protocol.
Ingest data
Protocols
Post metrics
You can write data to GreptimeDB using the /influxdb/write
API. Here’s an example of how to use this API:
- InfluxDB line protocol V2
- InfluxDB line protocol V1
curl -i -XPOST "http://localhost:4000/v1/influxdb/api/v2/write?db=public&precision=ms" \
--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" \
--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'
The /influxdb/write
supports query params including:
db
: Specifies the database to write to. The default value ispublic
.precision
: Defines the precision of the timestamp provided in the request body. Accepted values arens
(nanoseconds),us
(microseconds),ms
(milliseconds), ands
(seconds). The data type of timestamps written by this API isTimestampNanosecond
, so the default precision isns
(nanoseconds). If you use timestamps with other precisions in the request body, you need to specify the precision using this parameter. This parameter ensures that timestamp values are accurately interpreted and stored with nanosecond precision.
You can also omit the timestamp when sending requests. GreptimeDB will use the current system time (in UTC) of the host machine as the timestamp. For example:
- InfluxDB line protocol V2
- InfluxDB line protocol V1
curl -i -XPOST "http://localhost:4000/v1/influxdb/api/v2/write?db=public" \
--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" \
--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'
Authentication
GreptimeDB is compatible with InfluxDB’s line protocol authentication format, both V1 and V2. If you have configured authentication in GreptimeDB, you need to provide the username and password in the HTTP request.
- InfluxDB line protocol V2
- InfluxDB line protocol V1
InfluxDB’s V2 protocol uses a format much like HTTP’s standard basic authentication scheme.
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'
For the authentication format of InfluxDB’s V1 protocol. Add u
for user and p
for password to the HTTP query string as shown below:
curl 'http://localhost:4000/v1/influxdb/write?db=public&u=<username>&p=<password>' \
-d 'monitor,host=127.0.0.1 cpu=0.1,memory=0.4'
Telegraf
GreptimeDB’s support for the InfluxDB line protocol ensures its compatibility with Telegraf. To configure Telegraf, simply add GreptimeDB URL into Telegraf configurations:
- InfluxDB line protocol v2
- InfluxDB line protocol v1
[[outputs.influxdb_v2]]
urls = ["http://<host>:4000/v1/influxdb"]
token = "<greptime_user>:<greptimedb_password>"
bucket = "<db-name>"
## Leave empty
organization = ""
[[outputs.influxdb]]
urls = ["http://<host>:4000/v1/influxdb"]
database = "<db-name>"
username = "<greptime_user>"
password = "<greptimedb_password>"
Data model
While you may already be familiar with InfluxDB key concepts, the data model of GreptimeDB is something new to explore. Here are the similarities and differences between the data models of GreptimeDB and InfluxDB:
- Both solutions are schemaless, eliminating the need to define a schema before writing data.
- The GreptimeDB table is automatically created with the merge_mode option set to
last_non_null
. That means the table merges rows with the same tags and timestamp by keeping the latest value of each field, which is the same behavior as InfluxDB. - In InfluxDB, a point represents a single data record with a measurement, tag set, field set, and a timestamp. In GreptimeDB, it is represented as a row of data in the time-series table, where the table name aligns with the measurement, and the columns are divided into three types: Tag, Field, and Timestamp.
- GreptimeDB uses
TimestampNanosecond
as the data type for timestamp data from the InfluxDB line protocol API. - GreptimeDB uses
Float64
as the data type for numeric data from the InfluxDB line protocol API.
Consider the following sample data borrowed from InfluxDB docs as an example:
_time | _measurement | location | scientist | _field | _value |
---|---|---|---|---|---|
2019-08-18T00:00:00Z | census | klamath | anderson | bees | 23 |
2019-08-18T00:00:00Z | census | portland | mullen | ants | 30 |
2019-08-18T00:06:00Z | census | klamath | anderson | bees | 28 |
2019-08-18T00:06:00Z | census | portland | mullen | ants | 32 |
The data mentioned above is formatted as follows in the InfluxDB line protocol:
census,location=klamath,scientist=anderson bees=23 1566086400000000000
census,location=portland,scientist=mullen ants=30 1566086400000000000
census,location=klamath,scientist=anderson bees=28 1566086760000000000
census,location=portland,scientist=mullen ants=32 1566086760000000000
In the GreptimeDB data model, the data is represented as follows in the census
table:
+---------------------+----------+-----------+------+------+
| ts | location | scientist | bees | ants |
+---------------------+----------+-----------+------+------+
| 2019-08-18 00:00:00 | klamath | anderson | 23 | NULL |
| 2019-08-18 00:06:00 | klamath | anderson | 28 | NULL |
| 2019-08-18 00:00:00 | portland | mullen | NULL | 30 |
| 2019-08-18 00:06:00 | portland | mullen | NULL | 32 |
+---------------------+----------+-----------+------+------+
The schema of the census
table is as follows:
+-----------+----------------------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+-----------+----------------------+------+------+---------+---------------+
| location | String | PRI | YES | | TAG |
| scientist | String | PRI | YES | | TAG |
| bees | Float64 | | YES | | FIELD |
| ts | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| ants | Float64 | | YES | | FIELD |
+-----------+----------------------+------+------+---------+---------------+