Configuring Container Log Collection Paths

AOM can collect and display container logs. To use this function, first configure a log collection path according to the following procedure.

Precautions

  • The ICAgent only collects *.log, *.trace, and *.out text log files.
  • AOM collects standard container output logs by default.

Procedure

Adding a Log Policy on CCE

  1. When creating a workload on Cloud Container Engine (CCE), click Log Policies after adding a container.
  2. Click Add Log Policy. On the displayed page, configure parameters as required. The following uses Nginx as an example.

    Figure 1 Adding a log policy

  3. Set Storage Type to Host Path or Container Path.

    • Host Path: You can mount a host path to a specified container path. Set parameters according to the following table.
      Table 1 Parameters for adding log policies (host path)

      Parameter

      Description

      Storage Type

      Set this parameter to Host Path. You can mount a host path to a specified container path.

      Add Container Path

      *Host Path

      Host path to which a container log file is mounted. Example: /var/paas/sys/log/nginx

      Container Path

      Container path to which a logical data volume is mounted. Example: /tmp
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run. Otherwise, the container becomes abnormal. You are advised to mount log files to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. Otherwise, files will be replaced, causing container startup failures or workload creation failures.
      • If the volume is mounted to a high-risk directory, you are advised to use an account with minimum permissions to start the container; otherwise, high-risk files on the host may be damaged.
      • AOM collects only the first 20 log files that have been modified recently. It collects files from two levels of subdirectories by default.
      • AOM only collects .log, .trace, and .out text log files in mounting paths.

      Extended Host Path

      Level-3 directory added to the original volume directory or subdirectory. This path enables you to obtain output files of a single pod more easily.

      • None: No extended paths are configured.
      • PodUID: Pod ID.
      • PodName: Pod name.
      • PodUID/ContainerName: Pod ID/container name.
      • PodName/ContainerName: Pod name/container name.

      Collection Path

      Path for collecting logs precisely. Details are as follows:

      • If no collection path is specified, log files in .log, .trace, and .out formats will be collected from the current path by default.
      • If a collection path contains double asterisks (**), log files in .log, .trace, and .out formats will be collected from 5 levels of subdirectories.
      • If a collection path contains an asterisk (*), a fuzzy match is performed.

      Example: If the collection path is /tmp/**/test*.log, all .log files prefixed with test will be collected from /tmp and its 5 levels of subdirectories.

      CAUTION:

      To use the collection path function, ensure that the ICAgent version is 5.12.22 or later.

      Log Dumping

      Log dumping here refers to rolling local log files.

      • Enabled: AOM scans log files every minute. When a log file exceeds 50 MB, it is dumped immediately. A new .zip file is generated in the directory where the log file is located. For a log file, AOM stores only the latest 20 .zip files. When the number of .zip files exceeds 20, earlier .zip files will be deleted. After the dump is complete, the log file in AOM will be cleared.
      • Disabled: If you select Disabled, AOM does not dump log files.
      NOTE:
      • AOM log file rolling is implemented in the copytruncate mode. During configuration, ensure that log files are written in the append mode. Otherwise, file holes may occur.
      • Currently, mainstream log components such as Log4j and Logback support log file rolling. If your log files already support rolling, skip the configuration. Otherwise, conflicts may occur.
      • You are advised to configure log file rolling for your own services to flexibly control the size and number of rolled files.
    • Container Path: Logs will be stored in a container path. No host path needs to be mounted into the container. Set parameters according to the following table.

      Ensure that the ICAgent version is 5.10.79 or later.

      Table 2 Parameters for adding log policies (container path)

      Parameter

      Description

      Storage Type

      Set this parameter to Container Path.

      Logs will be stored in a container path. No host path needs to be mounted into the container. Ensure that the ICAgent version is 5.10.79 or later.

      Add Container Path

      Container Path

      Container path to which a logical data volume is mounted. Example: /tmp
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run. Otherwise, the container becomes abnormal. You are advised to mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. Otherwise, files will be replaced, causing container startup failures or workload creation failures.
      • If the volume is mounted to a high-risk directory, you are advised to use an account with minimum permissions to start the container; otherwise, high-risk files on the host may be damaged.
      • AOM collects only the first 20 log files that have been modified recently. It collects files from two levels of subdirectories by default.
      • AOM only collects .log, .trace, and .out text log files in mounting paths.

      Collection Path

      Path for collecting logs precisely. Details are as follows:

      • If no collection path is specified, log files in .log, .trace, and .out formats will be collected from the current path by default.
      • If a collection path contains double asterisks (**), log files in .log, .trace, and .out formats will be collected from 5 levels of subdirectories.
      • If a collection path contains an asterisk (*), a fuzzy match is performed.

      Example: If the collection path is /tmp/**/test*.log, all .log files prefixed with test will be collected from /tmp and its 5 levels of subdirectories.

      CAUTION:

      To use the collection path function, ensure that the ICAgent version is 5.12.22 or later.

      Log Dumping

      Log dumping here refers to rolling local log files.

      • Enabled: AOM scans log files every minute. When a log file exceeds 50 MB, it is dumped immediately. A new .zip file is generated in the directory where the log file is located. For a log file, AOM stores only the latest 20 .zip files. When the number of .zip files exceeds 20, earlier .zip files will be deleted. After the dump is complete, the log file in AOM will be cleared.
      • Disabled: If you select Disabled, AOM does not dump log files.
      NOTE:
      • AOM log file rolling is implemented in the copytruncate mode. During configuration, ensure that log files are written in the append mode. Otherwise, file holes may occur.
      • Currently, mainstream log components such as Log4j and Logback support log file rolling. If your log files already support rolling, skip the configuration. Otherwise, conflicts may occur.
      • You are advised to configure log file rolling for your own services to flexibly control the size and number of rolled files.

Adding a Log Policy on ServiceStage

  1. When deploying a component on ServiceStage, add an image, click Advanced Settings, and then click the Container Log tab.
  2. Add a log policy.

    The procedure for adding log policies on ServiceStage is the same as that on CCE. For details, see 3.

Adding a Log Policy on CCI

  1. When creating a deployment on Cloud Container Instance (CCI), select an image, and then click Advanced Settings and the Log Collection tab.
  2. Add a log policy.

    Click Add Log Storage and configure a log policy according to Table 3.

    Figure 2 Adding a log policy on CCI
    Table 3 Parameter description

    Parameter

    Description

    Container Log Path

    Ensure that the log output path is consistent with the container log path, so that logs can be written to the log storage volume.

    NOTICE:
    • After the log storage volume is mounted, the existing content under the log path will be overwritten. Ensure that the log path is independent. Otherwise, the original content cannot be seen.
    • AOM collects only the first 20 log files that have been modified recently. It does not collect files from subdirectories.
    • AOM only collects .log, .trace, and .out text log files in log paths.

    Log Storage Space

    Space of log storage.

    AOM processes logs in the unit of 50 MB to prevent them from being oversized. AOM stores only the latest 20 .zip files. When the number of .zip files exceeds 20, earlier .zip files will be deleted.

Viewing Container Logs

After the log collection paths are configured, the ICAgent collects log files from them. This operation takes about 1 minute to complete. After collecting logs, you can perform the following operations:

  • Viewing Container Log Files

    In the navigation pane, choose Log > Log Files. On the Component tab, select the corresponding cluster, namespace, and component to view log files, as shown in the following figure. For details, see Viewing Log Files.

    Figure 3 Viewing container log files
  • Viewing and Analyzing Container Logs

    In the navigation pane, choose Log > Log Search. On the Component tab, select the corresponding cluster, namespace, component, and file to view and analyze the collected logs. For details, see Searching for Logs.

    Figure 4 Viewing and analyzing container logs