Updated on 2023-11-28 GMT+08:00

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 the CCE console, add a container. Then, expand Log Policies.
  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. Mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. Otherwise, the files will be replaced, causing container startup failures or workload creation failures.
      • If the volume is mounted to a high-risk directory, 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. Mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. Otherwise, the files will be replaced, causing container startup failures or workload creation failures.
      • If the volume is mounted to a high-risk directory, 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

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 2 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 3 Viewing and analyzing container logs