By default, IoT Platform stores logs in the console for 7 days. You can export IoT Platform logs to a Logstore in Simple Log Service for long-term storage. After you enable log export, you can query and analyze logs, view and subscribe to log reports, and configure alert notifications in the IoT Platform console.
Prerequisites
Simple Log Service is enabled. For more information, see Get started with Simple Log Service.
Usage notes
IoT Platform does not support directly exporting or downloading log files. To obtain, export, or back up IoT Platform logs, you must enable the log export feature to export logs in real time to a Logstore in Simple Log Service for query, analysis, and long-term storage.
The log export feature is available only to Alibaba Cloud accounts.
Exporting logs to a Logstore in Simple Log Service incurs fees. For more information, see Billing of Simple Log Service.
Enable IoT Platform log export
You must enable the log export feature for each product individually.
- Log on to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
- In the navigation pane on the left, choose .
- Select a product and click the Export IoT Platform Logs tab.
- Click Enable Now.
- In the dialog box that appears, follow the instructions to enable log export.Note If Simple Log Service is not enabled, clicking Enable Now redirects you to the page where you can enable it.
- Click Create next to Role and Log Export Destination.Note If Created is displayed next to Role and Log Export Destination, you can skip this step.
- Click OK.
After you enable log export for a product, a log storage location and a service-linked role for log export are automatically created.- Service-linked role for log export: This role is used to grant log export permissions. For more information, see Role description.
- Log storage location:
- Project:
iot-log-${uid}-${regionId}. In this name,${uid}is your Alibaba Cloud account ID, and${regionId}is the region where your IoT Platform service resides. - Logstore: iot-logs.
All your products share this storage location. Different products are distinguished by the ProductKey keyword in the log content. For more information about logs, see IoT Platform logs.
- Project:
- Click Create next to Role and Log Export Destination.
- Set the data retention period.Exported logs are deleted after the specified data retention period. The default retention period is 7 days. You can set the retention period to a value from 1 to 3000 days, or select permanent retention.
On the Export IoT Platform Logs tab, click Set Data Retention Period. You are redirected to the Logstore management page. Then, click Modify, set the Data Retention Period, and click Save.
Use the log query and analysis feature
After you enable IoT Platform log export, you can perform the following operations on the Export IoT Platform Logs tab:
- On the Raw Logs tab:
Operation Description Query and analyze logs On the Raw Logs tab, use SQL statements to query logs within a specified time range and perform statistical analysis. For more information about SQL syntax, see Query syntax and features and Analysis syntax. Statistical Charts On the Statistical Charts tab, view the generated statistical charts. LogReduce On the LogReduce tab, aggregate logs with high similarity to quickly get an overview of your logs. Field Settings After you query logs, quickly analyze the distribution of a specific field in the query results. Configure Alerts When an alert is triggered, the system sends alert information through methods such as text messages, voice calls, emails, and DingTalk robots. - On the Log Reports tab:
Operation Description View Reports View log reports for a specified time range. Log reports show the operational status and abnormal issues of devices. For a list of included items, see Table 1. Report descriptions. By default, reports show data from the last hour, and the time granularity for line charts is 1 minute.
- You can click the blue time setting drop-down list in the upper-right corner of the page, or click
> Select Time Range in the upper-right corner of a single report to set the time range. - On the Raw Logs tab, use SQL to set the time granularity of line charts. For more information about the syntax, see Date and time functions.
For example, use
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 1440to set the time granularity to 1 hour.
Subscribe to Reports The system periodically renders reports as images and sends them to specified personnel by email or through DingTalk robots. Table 1. Report descriptions Report Display Style Description Device online/offline count Line chart Shows the number of times that devices went online and offline within a specified time range. Number of mobile originated/terminated messages Line chart Shows the number of mobile originated and mobile terminated messages within a specified time range. Top 20 devices by mobile originated/terminated message volume List Shows the 20 devices with the highest volume of mobile originated or mobile terminated messages, along with the message volumes. Distribution of data parsing script error codes Pie chart Shows the distribution of error codes that occurred during script parsing within a specified time range. You can query logs by error code to view the details of script parsing errors and optimize your scripts accordingly.
Top 10 devices with data parsing script errors List Shows the 10 devices with the most script parsing errors within a specified time range and their corresponding error counts. You can query logs by device DeviceName to view the details of script parsing errors and optimize your scripts accordingly.
Distribution of Thing Specification Language (TSL) model validation error codes Pie chart Shows the distribution of TSL model validation error codes within a specified time range. You can query logs by error code to view the details of TSL model validation errors and troubleshoot the issues.
Top 10 devices with TSL model validation errors List Shows the 10 devices with the most TSL model validation errors within a specified time range and their corresponding error counts. You can query logs by device DeviceName to view the details of TSL model validation errors and troubleshoot the issues.
Server-side subscription message volume Line chart Shows the volume of messages forwarded through AMQP and MNS server-side subscriptions within a specified time range. Last 20 abnormal device message records Pie chart Shows the last 20 abnormal device message records within a specified time range. You can query logs by device DeviceName and error code to view the details of abnormal device messages and troubleshoot the issues.
Number of data forwarding messages Line chart Shows the volume of messages forwarded to other cloud services within a specified time range. Last 20 abnormal rules engine forwarding records List Shows the last 20 abnormal rules engine forwarding records within a specified time range. You can query logs by device DeviceName and error code to view the details of abnormal rules engine forwarding and troubleshoot the issues.
Distribution of cloud API call errors Pie chart Shows the distribution of cloud API call errors within a specified time range. You can query logs by API name and use the log details and error codes to troubleshoot the issues.
- You can click the blue time setting drop-down list in the upper-right corner of the page, or click
Disable IoT Platform log export
You can disable the log export feature for a specific product at any time to save storage space.
- In the IoT Platform console, go to the Instance Overview page and click the card of the target instance.
- In the navigation pane on the left, choose .
- Select a product and click the Export IoT Platform Logs tab.
- Click Disable Export, and then click Confirm.After you disable log export for the product, new IoT Platform logs are no longer exported to the Logstore. The exported logs are retained until the specified data retention period ends and are then deleted.