Forward data to Time Series Database (TSDB)

更新时间:
复制 MD 格式

You can configure data forwarding rules to forward processed data to a Time Series Database (TSDB) instance for storage. This topic describes how to forward data to a data destination.

Prerequisites

  • An IoT Platform instance whose data can be forwarded to TSDB is created in a region that supports data forwarding to TSDB. For more information, see Feature availability by region.

  • A TSDB instance is created in a virtual private cloud (VPC) in the China (Shanghai) region. For more information, see the Time Series Database (TSDB) documentation.
    Important You can no longer purchase new Time Series Database (TSDB) instances after April 6, 2022. We recommend that you forward data to Lindorm. For more information, see Forward data to Lindorm.

    You can still renew and upgrade TSDB instances that were purchased before April 6, 2022.

  • You have created a data forwarding rule and written the SQL for data processing. For more information, see Set data forwarding rules.

Background information

After you configure the data destination, IoT Platform automatically completes the following configurations to forward device data from the rules engine to Time Series Database (TSDB).

  • IoT Platform uses two IP addresses from the virtual switch where the TSDB instance is located. The IPv4 CIDR block of the virtual switch is added to the whitelist of the TSDB instance.
  • A managed security group is created in the VPC where the TSDB instance is located. The security group name starts with sg-nsm- by default.

Limits

  • Data can only be forwarded within the same region. For example, data from an IoT Platform instance in China (Shanghai) can only be forwarded to a TSDB instance in China (Shanghai).
  • Data can only be forwarded to TSDB instances in a virtual private cloud (VPC).
  • Only data in JSON format can be forwarded.
  • In a forwarded message, all fields are written to the Time Series Database as metrics, except for the fields configured as the timestamp and tag values. The metric data type supports numeric values and strings. Other data types cause the write operation to fail.

Usage notes

Both the new and old versions of the data forwarding feature support forwarding data to Time Series Database (TSDB). For an example of how to use the new version, see New version: Forward data to Time Series Database (TSDB).

Procedure

  1. Log on to the IoT Platform console.

  2. On the Overview page, find the instance that you want to manage and click the instance ID or instance name.

  3. In the navigation pane on the left, choose Message Forwarding > Data Forwarding.

  4. Find the rule that you want to manage and click View in the Actions column. The Data Forwarding Rule page appears.

    Important

    If the new version of the data forwarding page is displayed, click Back to Old Version in the upper-right corner. Then, find the destination rule and click View.

  5. In the Forward Data section, click Add Operation.

  6. In the Add Operation dialog box, set Operation to Store data in Time Series Database (TSDB). Configure the other parameters and click Confirm.
    ParameterDescription
    Select an operationSelect Store data in Time Series Database (TSDB).
    RegionThis parameter is fixed to the region where your IoT Platform instance resides: China (Shanghai).
    TSDB InstanceSelect the TSDB instance in your virtual private cloud (VPC) as the data destination.
    Metric Data TypeSelect the data type for the metric. Numeric and String are supported.

    For more information, click the help icon 帮助.

    timestampThe timestamp. The following formats are supported:
    • Use a ${} expression, such as ${time}. This expression gets the value of the time field from the source topic message.
    • Use the data forwarding function timestamp(). This function gets the timestamp from the data forwarding server.
    • Enter a value. The value must be a UNIX timestamp, such as 1404955893000.
    Tag NameThe name of the tag used to mark data. Chinese characters, letters, digits, and special characters are supported. Special characters include colons (:), commas (,), periods (.), single quotation marks ('), forward slashes (/), hyphens (-), underscores (_), parentheses (()), and square brackets ([]).
    Tag ValueThe value of the tag. The following formats are supported:
    • Use a ${} expression. For example, if the source topic message contains a location property with the identifier city, you can set the tag value to ${city}. This expression gets the value of the city field from the message. This method is recommended.
    • Use a function supported by data forwarding, such as deviceName(). This function gets the device name as the tag value. For a list of supported functions, see Functions.
    • Enter a constant, such as beijing. Chinese characters, letters, digits, and special characters are supported. Special characters include colons (:), commas (,), periods (.), single quotation marks ('), forward slashes (/), hyphens (-), underscores (_), parentheses (()), and square brackets ([]).
    Note
    • You can add up to eight tag names and tag values.
    • Ensure that TSDB can obtain the configured tag names and values. If any tag name or value cannot be obtained, the write operation to the database will fail.
    RoleGrant IoT Platform the permissions to write data to TSDB.
  7. Return to the Data Forwarding page. Find the rule and click Start to enable the rule.

Data forwarding example

Example SQL for the rule:

SELECT time, city, power, distance FROM "/alprodu****/myDevice/user/update";

The rules engine processes and writes data to TSDB based on the SQL.

  1. The following code shows an example of a forwarded message processed by the SQL:

    {
    "time": 1513677897,
    "city": "beijing",
    "distance": 8545,
    "power": 93.0
    }
  2. Based on the configured data forwarding operation, the rules engine writes two data entries to TSDB.

    The example data written to TSDB is as follows:

    • Data: timestamp:1513677897, [metric:power value:93.0]
      tag: cityName=beijing
    • Data: timestamp:1513677897, [metric:distance value:8545]
      tag: cityName=beijing

    Description of the data written to TSDB:

    In the forwarded message, all fields are written to the Time Series Database as metrics, except for the time field, which is configured as the timestamp, and the city field, which is configured as a tag value. The remaining fields, power and distance, are written as metrics.

Operation example

Monitor building environments using TSDB