By default, the device log feature of IoT Platform allows you to retain the logs of the last seven days. This feature also allows you to export IoT Platform logs to a Logstore of Log Service for persistent storage. After you enable the IoT Platform log dump feature, you can query and analyze logs, view and subscribe to log reports, and configure alerts in the IoT Platform console.

Prerequisites

Log Service is activated. For more information, see Resource management overview.

Enable the IoT Platform log dump feature

Note The log dump feature is available only for Alibaba Cloud accounts.

You must enable the log dump feature for each product.

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance and click the instance name to go to the Instance Details page.
    Notice Enterprise Edition instances are available only in the Japan (Tokyo) region. If your IoT Platform is not activated in the Japan (Tokyo) region, skip this step.
    Overview
  3. In the left-side navigation pane, choose Maintenance > Device Log.
  4. Select a product and click the IoT Platform Log Dump tab.
  5. Click Enable.
  6. In the Log Configurations message, read the instructions and click OK.
    Note If Log Service is not activated, you are navigated to the activation page of Log Service after you click Enable.
    After you enable the IoT Platform log dump feature for the product, IoT Platform automatically creates a log storage location and a service-linked role that is used to export logs.
    • Log storage location:
      • Project: iot-log-${uid}-${regionId}. Replace the ${uid} variable with your Alibaba Cloud account ID and the ${regionId} variable with the ID of the region in which IoT Platform is activated.
      • Logstore: iot-logs.

      All products share the log storage location. You can find the logs of a product based on the specified ProductKey. For more information, see IoT Platform logs.

    • Service-linked role: You can use this role to obtain permissions to export logs. For more information, see AliyunServiceRoleForIoTLogExport service-linked role.
  7. Specify the retention period of logs.
    If the specified retention period of exported logs ends, the logs are deleted. By default, IoT Platform allows you to retain the logs of the last seven days. You can set the retention period to 1 to 3,000 days or permanent.

    On the IoT Platform Log Dump tab, click Set log save time. In the message that appears, click OK. On the Logstore Attributes page, click Modify, set the Data Retention Period parameter, and then click Save.

Use the log search and analysis feature

After you enable the IoT Platform log dump feature, you can perform the following operations on the tabs of the IoT Platform Log Dump tab:

  • Raw Logs tab
    Operation Description
    Query and analyze logs On the Raw Logs tab, you can use an SQL statement to query logs within a specified period of time and perform statistical analysis. For more information about SQL syntax, see Search syntax and Log analysis overview.
    View charts On the Graph tab, you can view the generated charts.
    Aggregated logs On the LogReduce tab, you can view aggregated logs with high similarity to get a full view of logs.
    Perform quick analysis After you search for logs, you can view the distribution of a field based on the search results.
    Configure an alert rule If an alert condition is met, IoT Platform sends an alert by using a notification method such as a text message, phone call, email, or DingTalk notification.
  • Log Report tab
    Operation Description
    View reports You can view log reports in a specified time range. Log reports reflect the statuses and exceptions of devices. For more information about log reports, see the following Log reports table.

    By default, a log report shows the data of the last one hour (time frame). The time interval for a line chart is one minute.

    • To specify a time range, you can click Time Range in the upper-right corner of the Log Report tab or choose More icon > Select Time Range in the upper-right corner of a report chart.
    • To set a time interval for a line chart, you can write an SQL statement on the Raw Logs tab. For more information about SQL syntax, see Date and time functions.

      For example, you can use the bizCode:device | SELECT date_format(date_trunc('hour',__time__), '%m-%d %H:%i') AS Time, count(1) AS count , operation GROUP BY Time, operation ORDER BY Time limit 1440 statement to set the time interval to one hour.

    Subscribe to reports IoT Platform converts reports into images on a regular basis and sends these images to the specified contacts by using emails or DingTalk chatbots.
    Table 1. Log reports
    Report Chart type Description
    Number of Times Device Online & Offline Line chart The line chart shows the number of times that devices are connected to IoT Platform and the number of times that devices are disconnected from IoT Platform in a specified period of time.
    Device Uplink & Downlink Messages Line chart The line chart shows the number of upstream messages and the number of downstream messages in a specified period of time.
    Top 20 Devices by Uplink&Downlink Message List The list shows the top 20 devices that send or receive the most upstream or downstream messages, and the number of messages of each device.
    Error Distribution for Data Parsing Script Pie chart The pie chart shows the distribution of data parsing errors in a specified period of time.

    You can search for logs by error code and view the details of data parsing errors in logs. This helps efficiently improve a data parsing script.

    Top 10 Devices by Data Parsing Script Error List The list shows the top 10 devices on which the most data parsing errors occur, and the number of errors that occur on each device in a specified period of time.

    You can search for logs by device name and view the details of data parsing errors in logs. This helps efficiently improve a data parsing script.

    Error Distribution for TSL Validation Pie chart The pie chart shows the distribution of Thing Specification Language (TSL) validation errors in a specified period of time.

    You can search for logs by error code, view the details of TSL validation errors in logs, and troubleshoot errors.

    Top 10 Devices by TSL Validation Error List The list shows the top 10 devices on which the most TSL validation errors occur, and the number of errors that occur on each device in a specified period of time.

    You can search for logs by device name, view the details of TSL validation errors in logs, and troubleshoot errors.

    Server-side Subscription Messages Forwarded Line chart The line chart shows the total number of messages that are forwarded by an Advanced Message Queuing Protocol (AMQP) or Message Service (MNS) server-side subscription in a specified period of time.
    Last 20 Device Anomaly Messages Pie chart The pie chart shows the last 20 device anomaly messages.

    You can search for logs by device name and error code, view the details of device anomaly messages in logs, and troubleshoot errors.

    Cloud Service Messages Forwarded Line chart The line chart shows the total number of messages that are forwarded by the data forwarding feature in a specified period of time.
    Last 20 Data Forwarding Errors List The list shows the last 20 data forwarding errors of the rules engine in a specified period of time.

    You can search for logs by device name and error code, view the details of data forwarding errors for the rules engine in logs, and troubleshoot errors.

    Error Distribution for Cloud API Calls Pie chart The pie chart shows the distribution of errors in API calls in a specified period of time.

    You can search for logs by API operation name and troubleshoot errors based on log details and error codes.

Disable the IoT Platform log dump feature

You can disable the IoT Platform log dump feature for a specific product at any time as needed to save storage space.

  1. Log on to the IoT Platform console . On the Overview page, find the instance that you want to manage and click the instance.
  2. In the left-side navigation pane, choose Maintenance > Device Log.
  3. Select a product and click the IoT Platform Log Dump tab.
  4. Click Stop Dump. In the message that appears, click OK.
    After the IoT Platform log dump feature is disabled, the newly generated IoT Platform logs are no longer exported to your Logstore. Previous logs are not deleted until the specified retention period of these logs ends.