TSDB for InfluxDB® stores data as time series. This guide walks you through writing your first data points using the influx CLI and querying them back with InfluxQL SELECT statements.
Prerequisites
Before you begin, ensure that you have:
-
A TSDB for InfluxDB® instance created in the Alibaba Cloud Management Console
-
The influx CLI installed and connected to your instance (default port: 3242)
The influx CLI sends requests to the TSDB for InfluxDB® HTTP API. For curl-based examples, see Use the HTTP API to write data and Use the HTTP API to query data.
Data model
Every data point belongs to a measurement and consists of the following components:
| Component | Description | Example |
|---|---|---|
| Measurement | The metric being tracked — analogous to a table in SQL | cpu, temperature |
| Tag | Indexed key-value metadata used to filter and group results | host=serverA, region=us_west |
| Field | The measured value; at least one is required per data point | value=0.64, temp=21.2 |
| Timestamp | Unix nanosecond timestamp stored in the time column; optional on write |
1434067467000000000 |
Key differences from relational databases:
-
Indexes apply to tags, not fields.
-
TSDB for InfluxDB® never stores null values.
-
No schema definition is required before writing — it is schemaless.
-
TSDB for InfluxDB® can store millions of measurements.
Write data
Line protocol format
All writes use line protocol:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field-key>=<field-value>...] [unix-nano-timestamp]
Examples:
cpu,host=serverA,region=us_west value=0.64
payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3i 1434067467100293230
stock,symbol=AAPL bid=127.46,ask=127.48
temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000
For the full specification, see Line protocol reference.
Write a data point
In the influx CLI, use INSERT followed by a line protocol string:
> INSERT cpu,host=serverA,region=us_west value=0.64
>
This writes one data point to the cpu measurement with tags host=serverA and region=us_west, and a field value=0.64.
When you omit the timestamp, TSDB for InfluxDB® assigns the local server time at query time. The timestamp returned in query results may differ from the one in these examples.
To write a data point with multiple fields:
> INSERT temperature,machine=unit42,type=assembly external=25,internal=37
>
Query data
Query specific fields
Use SELECT to retrieve specific fields and tags from a measurement:
> SELECT "host", "region", "value" FROM "cpu"
name: cpu
------------
time host region value
2015-10-21T19:28:07.580664347Z serverA us_west 0.64
>
Query all fields and tags
Use the * operator to return all fields and tags:
> SELECT * FROM "temperature"
name: temperature
-----------------
time external internal machine type
2015-10-21T19:28:08.385013942Z 25 37 unit42 assembly
>
Avoid using * without a LIMIT clause on large databases — it may cause performance issues. Press Ctrl+C to cancel a long-running query.
Use regular expressions
TSDB for InfluxDB® supports Go-style regular expressions in queries:
> SELECT * FROM /.*/ LIMIT 1
> SELECT * FROM "cpu_load_short"
> SELECT * FROM "cpu_load_short" WHERE "value" > 0.9
Next steps
InfluxDB® is a trademark registered by InfluxData, which is not affiliated with, and does not endorse, TSDB for InfluxDB®.