Skip to main content
Version: nightly

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:

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'

The /influxdb/write supports query params including:

  • db: Specifies the database to write to. The default value is public.
  • precision: Defines the precision of the timestamp provided in the request body. Accepted values are ns (nanoseconds), us (microseconds), ms (milliseconds), and s (seconds). The data type of timestamps written by this API is TimestampNanosecond, so the default precision is ns (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:

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'

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'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'

Telegraf

GreptimeDB's support for the InfluxDB line protocol ensures its compatibility with Telegraf. To configure Telegraf, simply add GreptimeDB URL into Telegraf configurations:

[[outputs.influxdb_v2]]
urls = ["http://<host>:4000/v1/influxdb"]
token = "<greptime_user>:<greptimedb_password>"
bucket = "<db-name>"
## Leave empty
organization = ""

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_measurementlocationscientist_field_value
2019-08-18T00:00:00Zcensusklamathandersonbees23
2019-08-18T00:00:00Zcensusportlandmullenants30
2019-08-18T00:06:00Zcensusklamathandersonbees28
2019-08-18T00:06:00Zcensusportlandmullenants32

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 |
+-----------+----------------------+------+------+---------+---------------+

Reference