The log export tool allows you to export Message Service (MNS) logs from Object Storage Service (OSS) to Log Service(SLS) for query and analysis. This topic describes how to use the log export tool in the Windows operating system.

Description

The log export tool supports Python 2.6 and Python 2.7, and can run in the Windows and Linux operating systems.

  • Version: V1.0.0
  • Release date: April 20, 2016
  • New feature: Operation logs of MNS queues and topics can be exported from OSS to Log Service(SLS) for query and analysis.

Prerequisites

Preparations

  1. Install Python and pip.
    1. Visit the official website of Python and download the Python 2.7 package. Install Python to the D:\Python27 directory.
      Notice The D:\Python27 directory is used only for reference. You can specify the directory based on your business requirements.
    2. Specify the D:\Python2 directory for an environment variable.
    3. Visit the official website of pip. Download and decompress the pip-8.1.2.tar.gz package.
    4. Open the Command Prompt in Windows. You can also open the Windows PowerShell ISE if you are using Windows 7 or later. Go to the directory to which the pip-8.1.2.tar.gz package is decompressed and run the following command:
      python setup.py install
    5. Specify the D:\Python27\Scripts directory in which Python scripts are stored for an environment variable.
  2. Install the protobuf and simplejson compilers.
    1. Run the following command to install protobuf:
      pip install protobuf
    2. Run the following command to install Requests:
      pip install requests
    3. Run the following command to install simplejson:
      pip install simplejson

Export logs

Download and decompress the package of the log export tool to the mnslog_export directory. Click V1.0.0 to download the log export tool V1.0.0.

  • Run the following command to export logs:
    python2.7 mnslog_export.py --access_id=xxx --access_key=xxx --oss_host=xxx --log_bucket=xxx --sls_project=xxx --sls_logstore=xxx --sls_host=xxx --queue_name=xxx
  • Parameters
    Parameter Description
    access_id The AccessKey ID of the AccessKey pair that you create in the Resource Access Management (RAM) console. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.
    access_key The AccessKey secret of the AccessKey pair that you create in the RAM console. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.
    oss_host The OSS endpoint in the format of oss-<Region ID>.aliyuncs.com.
    log_bucket The name of the OSS bucket that stores MNS logs.
    start_time You can export the MNS logs that are generated in a specific period from OSS to Log Service. This parameter specifies the start time of the period. For example, 202103270102 indicates that the period starts from 01:02 on March 27, 2021.
    end_time You can export the MNS logs that are generated in a specific period from OSS to Log Service. This parameter specifies the end time of the period. For example, 202103270302 indicates that the period ends at 03:02 on March 27, 2021.
    sls_host The Log Service(SLS) endpoint in the format of <Region ID>.sls.aliyun.com.
    sls_project The name of the Log Service project to which MNS logs are imported.
    sls_logstore The name of the Logstore to which MNS logs are imported.
    queue_name The name of the MNS queue whose logs you want to export from OSS to Log Service. You can set only one of the queue_name and topic_name parameters.
    topic_name The name of the MNS topic whose logs you want to export from OSS to Log Service. You can set only one of the queue_name and topic_name parameters.
Note
  • You can export only the logs that were generated in the last seven days to Log Service(SLS). Otherwise, an error occurs.
  • After you run the mnslog_export.py command and upload MNS logs to Log Service(SLS), we recommend that you wait for 60 seconds before you log on to the Log Service console. Otherwise, you may fail to query the newly uploaded logs.

Query logs

You can log on to the Log Service console to query the logs 60 seconds after MNS logs are exported from OSS to Log Service(SLS).

  1. Log on to the Log Service console.
  2. In the Projects section, click the name of the project that you want to view.
  3. Choose Log Storage > Logstores. On the Logstores tab, click the Logstore that you want to view.
  4. Find the Logstore that you want to query, click the More icon icon on the right, and then select Search & Analysis.
  5. On the details page of the Logstore, select a time range and click Search & Analyze. All logs collected within the time range are displayed.
  6. Click a message ID to query all logs of the specified message.