All Products
Search
Document Center

Elastic Container Instance:Use coredump to analyze instance program exceptions

最終更新日:Nov 01, 2024

If a program unexpectedly terminates or stops responding, the operating system records the content of the random access memory (RAM) that is allocated to the program and saves the content to a file for subsequent debugging and analysis. This process is called a core dump. This topic describes how to enable the coredump feature for an elastic container instance. After you enable the coredump feature, you can view and analyze a core file to identify the cause of an issue and fix the program.

Background information

In a Linux system, if a program unexpectedly terminates or stops responding, the operating system records the status of the random access memory (RAM) that is allocated to the program and saves the status to a file. This process is called a core dump. You can view and analyze the core file that is generated from the core dump to identify the cause of the issue.

The following figure shows the signals that indicate core dumps in Linux. The values of the signals in the Action column are Core.

For more information, see Core dump file.

Description

By default, coredump is disabled in elastic container instances to prevent service unavailability that is caused by excessive disk usage. You can use one of the following methods to use coredump:

  • Method 1: Execute a coredump O&M task

    After you enable coredump, the system generates an O&M task. If a container unexpectedly terminates or exits, the system triggers coredump to generate a core file and save the core file to an Object Storage Service (OSS) bucket.

  • Method 2: Specify a path to store core files

    Elastic Container Instance allows you to use an external storage device to store core files. After you specify the storage device, coredump is automatically enabled for Elastic Container Instance. If a container unexpectedly terminates or exits, the system triggers coredump to generate a core file and save the core file to the specified external storage device.

Note
  • Method 1 is easy to use, but has limits on the regions that you specify and the validity periods of the O&M tasks. Method 1 is suitable for temporary program debugging and diagnostics.

    • Generated O&M tasks can be executed only once. After an O&M task is executed and a core file is generated, coredump is disabled. The validity period of an O&M task is 12 hours.

    • You cannot manually execute coredump O&M tasks for the following regions: China (Ulanqab), China (Heyuan), China (Guangzhou), China (Nanjing - Local Region), Philippines (Manila), South Korea (Seoul), and Thailand (Bangkok).

  • Method 2 requires an external storage device. You can use this method to acquire core files even if the program is unstable. However, if the program repeatedly restarts, a large number of core files may be generated.

Method 1: Execute a coredump O&M task

Use the Elastic Container Instance console

  1. Log on to the Elastic Container Instance console.

  2. Enable coredump for an instance.

    1. In the left-side navigation pane, click Container Group. On the Container Group page, click the ID of the instance for which you want to enable coredump to go to the instance details page.

    2. On the O&M tab, click the Core dump tab, and then click Enable.

      After you enable coredump, the system generates an O&M task. Before coredump is triggered, the task is in the Pending state.

      coredump-1

  3. Trigger coredump.

    Connect to the elastic container instance. After you run the following sleep 100 command in the container, press the Ctrl key and the \key at the same time to trigger coredump. A core file is automatically generated and saved to an OSS bucket.coredump2

  4. Download the core file.

    After coredump is triggered and the system generates a core file, the state of the O&M task changes to Successful. Click Download in the Result column to download the core file to your on-premises machine.

    coredump-2

    Note

    If the system does not respond, check the website permission settings of your browser.

Call an API operation

  1. Enable coredump for an instance.

    If you want to create an O&M task by calling the CreateInstanceOpsTask API operation, you must specify the instance for which you want to enable coredump and set the OpsType parameter to coredump and the OpsValue parameter to enable. For more information, see CreateInstanceOpsTask.

    Note

    Make sure that the CorePattern parameter is not set for the instance when you create the instance.

  2. Trigger coredump.

    Connect to the elastic container instance. After you run the following sleep 100 command in the container, press the Ctrl key and the \key at the same time to trigger coredump. A core file is automatically generated and saved to an OSS bucket.coredump2

  3. Download the core file.

    Call the DescribeInstanceOpsRecords API operation to query the result of the O&M task that is executed. The ResultContent response parameter indicates the OSS bucket path of the core file. You can download the core file from the path.

Method 2: Specify a path to store core files

Core files are used to analyze issues offline. In most cases, core files are stored on external storage devices instead of local storage of containers. This prevents loss of core files if containers terminate. Elastic Container Instance allows you to specify a path to store core files. After you specify a path, coredump is automatically enabled.

When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the CorePattern parameter to specify the path to store core files. The following table describes the parameters that are related to the path to store core files. For more information, see CreateContainerGroup.

Note

NFSVolume is used as the volume type in the following example. You must configure these parameters based on your actual volume type.

Parameter

Type

Example

Description

CorePattern

String

/data/dump-a/core

The path to store core files.

Important

The path cannot start with a vertical bar (|). You cannot use coredump to configure executable programs.

Volume.N.Name

String

volume1

The name of volume N.

Volume.N.Type

String

NFSVolume

The type of volume N. In this example, the value of this parameter is NFSVolume.

Volume.N.NFSVolume.Path

String

/dump

The path to the Network File System (NFS) volume.

Volume.N.NFSVolume.Server

String

143b24****-gfn3.cn-beijing.nas.aliyuncs.com

The endpoint of the server when you set the Volume.N.Type parameter to NFSVolume.

If you mount an Alibaba Cloud File Storage NAS file system, set the value to the domain name of the mount target of the NAS file system.

Container.N.VolumeMount.N.Name

String

volume1

The name of the volume that you want to mount to the container. The value is the same as the value of the Volume.N.Name parameter.

Container.N.VolumeMount.N.MountPath

String

/data/dump-a/

The directory to which volume N is mounted.

Data in this directory is overwritten by the data on the volume. Make sure that this value is correct.

The following part describes how to enable coredump if you use a NAS file system as an external storage.

  1. Create Elastic Container Instance A, mount a NAS file system to Elastic Container Instance A, and specify a path to store core files.

    When you call the CreateContainerGroup API operation to create Elastic Container Instance A, configure the following parameters to mount the /dump/ directory of the NAS file system to the /data/dump-a/ directory of the container and set the /data/dump-a/core path to store core files.

    ContainerGroupName=test-a
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    # Specify a volume
    Volume.1.Name=volume1
    Volume.1.Type=NFSVolume
    Volume.1.NFSVolume.Path=/dump/
    Volume.1.NFSVolume.Server=143b24****-gfn3.cn-beijing.nas.aliyuncs.com
    # Mount the volume to the container.
    Container.1.Name=nginx
    Container.1.Image=registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2
    Container.1.VolumeMount.1.Name=volume1
    Container.1.VolumeMount.1.MountPath=/data/dump-a/
    # Set the path to store the core file.
    CorePattern=/data/dump-a/core
  2. Trigger coredump in a directory of the container on Elastic Container Instance A.

    For example, after you run the sleep 100 command in the container, you can press the Ctrl key and the \ key at the same time to trigger coredump. The core file is saved to the /data/dump-a/ path of the container.

    coredump4

  3. Release Elastic Container Instance A.

  4. Mount the same NAS file system to Elastic Container Instance B.

    When you call the CreateContainerGroup API operation to create Elastic Container Instance B, configure the following parameters to mount the /dump/ directory of the NAS file system to the /data/dump-b/ directory of the container.

    ContainerGroupName=test-nas-b
    SecurityGroupId=sg-bp1daxpbz9lzpvvc****
    VSwitchId=vsw-bp1gds63lmlm7ib05****
    # Specify a volume
    Volume.1.Name=volume1
    Volume.1.Type=NFSVolume
    Volume.1.NFSVolume.Path=/dump/
    Volume.1.NFSVolume.Server=143b24****-gfn3.cn-beijing.nas.aliyuncs.com
    # Mount the volume to the container.
    Container.1.Name=nginx
    Container.1.Image=registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2
    Container.1.VolumeMount.1.Name=volume1
    Container.1.VolumeMount.1.MountPath=/data/dump-b/
  5. View the core file in the container of Elastic Container Instance B.

    The following figure shows that the core file is stored in the /data/dump-b/ path of the container. The core file is not lost after Elastic Container Instance A is released because the core file is stored in an external storage device.

    coredump5

FAQ

The system does not respond after coredump is triggered in the Elastic Container Instance console and I click Download in the Result column of the O&M task. What do I do?

If the system does not respond, check the website permission settings of your browser. For example, if you use Google Chrome, you can use the following method to allow the download:

  1. In the Elastic Container Instance console, click the 浏览器图标 icon in the address bar of your browser, and then select Site settings. 浏览器设置1

  2. Change the settings of the configuration item Insecure content to Allow. 浏览器设置2