The influx CLI is a lightweight tool that you can use to interact with databases. For information about how to download and use the CLI, see Command-line interface. By default, the CLI uses port 3242 to send requests to the HTTP API endpoints of TSDB for InfluxDB®. This way, the CLI can directly communicate with TSDB for InfluxDB®.
The CLI can also send native HTTP requests to databases. For more information, see curl command examples in the "Use the HTTP API to write data" and "Use the HTTP API to query data" topics.
Data reads and writes
After you create a TSDB for InfluxDB® instance in the Alibaba Cloud Management Console, you can read data from or write data to TSDB for InfluxDB®.
TSDB for InfluxDB® stores data based on time series. A time series contains a measurement, such as cpu_load or temperature. A time series can contain zero or multiple data points. Each data point indicates a measurement value. A data point consists of one timestamp, one
measurement, at least one key-value
field, and zero or multiple key-value
tags. The timestamp is stored in the
time column. A measurement is a metric that is used to measure attributes, such as cpu_load. A field is a measurement value, such as "value=0.64" or "temperature=21.2". A tag stores metadata, such as "host=server01", "region=EMEA", or "dc=Frankfurt".
measurement is similar to an SQL table in concept. In this table, the timestamp is always the primary index, and the
fields are the columns in the table. Indexes can be created on
fields. The difference is that TSDB for InfluxDB® can store millions of measurements and does not store null values. TSDB for InfluxDB® provides schemaless databases. Therefore, you do not need to predefine schemas.
Data points are written to TSDB for InfluxDB® by using the line protocol. The line protocol uses the following format:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]
The following examples show the format that you can use to write data points to TSDB for InfluxDB®:
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 more information about the line protocol, see Line protocol reference.
To write a single data point into TSDB for InfluxDB® by using the CLI, enter
INSERT and then enter the data point information. The following statement provides an example:
> INSERT cpu,host=serverA,region=us_west value=0.64 >
This example writes the specified data point to TSDB for InfluxDB®. In the data point, the measurement is
cpu, the tags are
region, and the
Execute the following statement to query the data point that is written:
> SELECT "host", "region", "value" FROM "cpu" > name: cpu ------------ time host region value 2015-10-21T19:28:07.580664347Z serverA us_west 0.64 >
In the preceding example, you did not specify a timestamp when you wrote the data point. For a data point that does not contain a timestamp, TSDB for InfluxDB® assigns the local current time as the timestamp to the data point when the data point is queried. Therefore, the timestamp that is returned for the data point can be different from the timestamp in the example.
Execute the following statement to write a data point that contains two fields in a measurement. The data type of the data point is different from that in the preceding example.
> INSERT temperature,machine=unit42,type=assembly external=25,internal=37 >
If you want to return all fields and tags for a query, you can use the
> SELECT * FROM "temperature" name: temperature ----------------- time external internal machine type 2015-10-21T19:28:08.385013942Z 25 37 unit42 assembly >
If you use the * operator instead of a LIMIT clause to query data from a large-scale database, performance issues may occur. You can use the Ctrl+C keyboard shortcut to cancel long-running queries.
TSDB for InfluxDB® also provides other features that are not described in this topic, such as support for regular expressions that comply with the Go style. The following statements provide examples:
> SELECT * FROM /.*/ LIMIT 1 -- > SELECT * FROM "cpu_load_short" -- > SELECT * FROM "cpu_load_short" WHERE "value" > 0.9
This quick start guide describes the steps that you must perform to write data to TSDB for InfluxDB® and query data from TSDB for InfluxDB®. For more information about how to write and query data, see Use the HTTP API to write data and Use the HTTP API to query data. For more information about the concepts related to TSDB for InfluxDB®, see Key concepts.
InfluxDB® is a trademark registered by InfluxData, which is not affiliated with, and does not endorse, TSDB for InfluxDB®.