InfluxDB Line Protocol

MynaDB uses the InfluxDB Line Protocol for data ingestion. This text-based format is simple, human-readable, and efficient for writing time series data.

💡 Compatibility

MynaDB is compatible with InfluxDB Line Protocol v1. If you're already using InfluxDB, Telegraf, or other tools that output Line Protocol, you can send data directly to MynaDB with minimal changes.

Line Protocol Syntax

Each line represents a single data point with the following format:

syntax
<measurement>[,<tag_key>=<tag_value>...] <field_key>=<field_value>[,<field_key>=<field_value>...] [<timestamp>]

Components

Component Required Description
measurement Yes The name of the measurement (like a table name)
tags No Key-value pairs for metadata (indexed, used for filtering)
fields Yes Key-value pairs for actual data values
timestamp No Unix timestamp in nanoseconds (defaults to server time)

Basic Examples

Simple Data Point

line-protocol
cpu usage=75.5

This creates a data point in the cpu measurement with a single field usage.

With Tags

cpu,host=server01,region=us-west usage=75.5,temperature=45

Tags are comma-separated key-value pairs after the measurement name. They're used for filtering and grouping.

With Timestamp

cpu,host=server01 usage=75.5 1609459200000000000

The timestamp is in nanoseconds since Unix epoch (January 1, 1970).

Multiple Fields

system,host=server01 cpu_usage=75.5,memory_used=8589934592,disk_free=107374182400

Data Types

Field Value Types

Type Syntax Example
Float Plain number or with decimal value=82.5 or value=82
Integer Number with i suffix count=100i
String Quoted with double quotes status="running"
Boolean true/false, t/f, TRUE/FALSE active=true
Unsigned Integer Number with u suffix bytes=1024u

Examples by Type

line-protocol
# Float (default for numbers)
temperature value=23.5

# Integer
requests count=1000i

# String
event message="Server started successfully"

# Boolean
status healthy=true

# Unsigned integer
network bytes_sent=1073741824u

# Mixed types in one line
server,host=web01 cpu=75.5,memory=8192i,status="ok",active=true

Writing Data via API

Single Line

bash
curl -X POST http://localhost:7000/write/mydb \
  -d 'cpu,host=server01,region=us-west usage=75.5,temperature=45'

Multiple Lines (Batch)

curl -X POST http://localhost:7000/write/mydb -d '
cpu,host=server01,region=us-west usage=75.5
cpu,host=server02,region=us-east usage=82.3
cpu,host=server03,region=eu-west usage=68.9
memory,host=server01 used=8589934592,total=17179869184
memory,host=server02 used=12884901888,total=17179869184
'

With Timestamps

curl -X POST http://localhost:7000/write/mydb -d '
cpu,host=server01 usage=75.5 1704067200000000000
cpu,host=server01 usage=76.2 1704067260000000000
cpu,host=server01 usage=74.8 1704067320000000000
'

Schema Strategy

MynaDB supports two schema strategies that determine how data is organized into schemas and tables. This is configured via schema.strategy.

ServiceAsSchema (Default)

The service tag becomes the schema name, measurement becomes the table name.

# Write with service tag
curl -X POST http://localhost:7000/write/mydb \
  -d 'cpu,service=webserver,host=web01 usage=75.5'

# Query: catalog.schema.table = mydb.webserver.cpu
curl -X POST http://localhost:7000/query/mydb \
  -d 'SELECT * FROM mydb.webserver.cpu'

ServiceAsTable

The service tag becomes the table name, measurement is stored as a tag.

# Write with service tag
curl -X POST http://localhost:7000/write/mydb \
  -d 'cpu,service=webserver,host=web01 usage=75.5'

# Query: catalog.schema.table = mydb.default.webserver
curl -X POST http://localhost:7000/query/mydb \
  -d 'SELECT * FROM mydb.default.webserver WHERE measurement = '\''cpu'\'''

Special Characters

Escaping Rules

Location Characters to Escape Escape With
Measurement name Comma, Space Backslash (\, \ )
Tag key/value Comma, Equals, Space Backslash (\, \= \ )
Field key Comma, Equals, Space Backslash (\, \= \ )
String field value Double quote, Backslash Backslash (\" \\)

Examples

# Escaped comma in measurement name
cpu\,usage,host=server01 value=75.5

# Escaped equals in tag value
event,equation=a\=b result=42

# Escaped quotes in string field
log,host=server01 message="Error: \"Connection refused\""

# Escaped backslash
path,host=server01 value="C:\\Users\\admin"

Timestamps

Precision

MynaDB accepts timestamps in nanosecond precision by default:

Precision Example Value Description
Nanoseconds 1704067200000000000 Default precision (19 digits)
Microseconds 1704067200000000 16 digits
Milliseconds 1704067200000 13 digits
Seconds 1704067200 10 digits

Generating Timestamps

bash
# Current time in nanoseconds (Linux)
date +%s%N

# Current time in nanoseconds (macOS)
python3 -c "import time; print(int(time.time() * 1e9))"

# Specific date to nanoseconds
date -d "2024-01-01 00:00:00" +%s%N

Best Practices

⚠ Performance Tips
  • Batch writes: Send multiple lines in a single request for better throughput
  • Limit tags: Use tags for low-cardinality metadata (host, region, service)
  • Use fields for values: Numeric data should be fields, not tags
  • Consistent schemas: Keep field types consistent across data points
  • Reasonable batch size: 5,000-10,000 lines per request is optimal

Good vs Bad Examples

line-protocol
# GOOD: Low-cardinality tags, numeric fields
cpu,host=server01,region=us-west usage=75.5,cores=8i

# BAD: High-cardinality tag (user_id has millions of values)
pageview,user_id=12345678 count=1

# GOOD: User ID as field instead
pageview,page=/home user_id="12345678",count=1i

# BAD: Numeric value as tag
temperature,value=75.5 dummy=1

# GOOD: Numeric value as field
temperature,sensor=outdoor value=75.5

Validation Errors

Common errors when writing line protocol data:

Error Cause Solution
Missing field No field values provided Add at least one field: cpu usage=75
Invalid timestamp Non-numeric timestamp Use Unix nanoseconds: 1704067200000000000
Type conflict Field type changed (e.g., float to string) Keep field types consistent
Empty measurement Line starts with comma or space Provide measurement name first

Integration with Telegraf

Configure Telegraf to send data to MynaDB:

toml
[[outputs.influxdb]]
  urls = ["http://localhost:7000"]
  database = "mydb"
  skip_database_creation = true

  # Use /write endpoint
  [outputs.influxdb.tagpass]

[[inputs.cpu]]
  percpu = true
  totalcpu = true

[[inputs.mem]]

[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs"]

See Also