You need to enable JavaScript to run this app.
导航

修改 LogCollector 资源配置

最近更新时间2024.02.27 14:19:48

首次发布时间2024.02.27 14:19:48

为避免 LogCollector 过度消耗服务器的资源,从而影响其他服务的正常运行,日志服务对 LogCollector 采集性能做了限制。当您需要提高 LogCollector 采集性能时,可调整允许 LogCollector 使用的 CPU 阈值和内存阈值。本文档介绍修改 LogCollector 资源配置的方法。

设置场景

遇到以下场景时,可修改 LogCollector 的资源配置。

  • 需要采集的日志文件数目大(例如同时采集的文件数超过 100 个),占用大量内存。
  • 日志数据流量大,导致 LogCollector CPU 占用率高。
  • 查询日志时,发现存在采集延迟。

修改配置

宿主机环境

  1. filebeat-7.12.0/etc 目录中找到 LogCollector 配置文件 filebeat.yml

  2. filebeat.yml 中,添加 max_procsmax_mem 配置项。

    配置项

    说明

    示例

    max_procs

    允许 LogCollector 使用的 CPU 阈值。相关说明如下:

    • 最小值为 1。
    • 最大值为当前机器的 CPU 核数。
    • 取值为正整数。
    • 默认值为 1。

    max_procs: 2

    max_mem

    允许 LogCollector 使用的内存阈值。相关说明如下:

    • 取值为正整数,GB 级别或 MB 级别,例如 2 GB,2 MB。
    • 默认值为 1GB。

    说明

    max_mem 为软限制,实际 LogCollector 占用的内存可能超过限制值。

    max_mem: 2GB

    配置文件示例如下:

    filebeat:   
    
    max_procs: 2              #-- 表示可使用的CPU核数
    max_mem: 2GB              #-- 表示可使用的内存大小 
    
    output.tls:
      endpoint: 'https://tls-cn-beijing.ivolces.com'  #--日志服务的服务地址
      secret_id: Your Secrect Id                      #--火山引擎账号密钥Access Key ID。
      secret_key: Your Secrect Key                    #--火山引擎账号密钥Secret Access Key。
      region: cn-beijing                              #--日志项目的所在地域(Region)。
      compress_type: lz4                              #--压缩类型,建议维持默认设置lz4
      ip: 10.1.x.x                                    #--手动指定的宿主机 IP 地址
    logging.level: info                               #--filebeat日志级别
    logging.to_files: true
    logging.files:
      name: filebeat
      keepfiles: 7
      permissions: 0644
    

Kubernetes 环境

  1. 找到配置文件。
    该配置文件为您在安装 LogCollector 时创建的文件。详细说明如下:

    • Daemonset 方式:创建 Daemonset 时创建的文件。详细说明请参考5 创建 Daemonset
    • Sidecar 方式:创建 Sidecar 配置时创建的文件。详细说明请参考2 创建 Sidecar 配置
  2. 在配置文件中,修改 limits 节点下的 cpumemory 字段。

    说明

    在 Kubernetes 环境中,LogCollector 资源阈值受限于 Kubernetes 限制。

    配置项

    说明

    示例

    cpu

    允许 LogCollector 使用的 CPU 阈值。

    cpu: '2'

    memory

    允许 LogCollector 使用的内存阈值。

    memory: 2GB

    配置文件示例如下:

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: logcollector
      namespace: ${namespace}
      labels:
        k8s-app: logcollector
    spec:
      selector:
        matchLabels:
          k8s-app: logcollector
      template:
        metadata:
          labels:
            k8s-app: logcollector
        spec:
          serviceAccountName: logcollector
          terminationGracePeriodSeconds: 30
          containers:
            - name: logcollector
              image: ${logcollector-image}
              imagePullPolicy: Always
              args:
                - /usr/local/container/filebeat-7.12.0/filebeat
                - -c
                - /usr/local/container/filebeat-7.12.0/etc/filebeat.yml
              securityContext:
                runAsUser: 0
                # If using Red Hat OpenShift, uncomment this:
                # privileged: true
              livenessProbe:
                initialDelaySeconds: 10
                periodSeconds: 10
                exec:
                  command:
                    - sh
                    - -c
                    - |
                      filebeat_num=`ps -ef 2>/dev/null | grep "filebeat" | grep -v "grep" | wc -l`
                      if [ $filebeat_num -eq 0 ]; then
                        return 1
                      fi
              resources:
                limits:
                  cpu: '2'
                  memory: 2GB
                requests:
                  cpu: '1'
                  memory: 1GB
              volumeMounts:
                - name: logcollector-config
                  mountPath: /usr/local/container/filebeat-7.12.0/etc/
                  readOnly: true
                - name: logcollector-host
                  mountPath: /logcollector_host
                  mountPropagation: HostToContainer
                  readOnly: true
                - name: logcollector-data
                  mountPath: /usr/local/container/filebeat-7.12.0/data
              env:
                - name: MAX_MEM
                  valueFrom:
                    resourceFieldRef:
                      containerName: logcollector
                      resource: limits.memory
          volumes:
            - name: logcollector-config
              configMap:
                defaultMode: 420
                name: logcollector-config
            - name: logcollector-host
              hostPath:
                path: /
            - name: logcollector-data
              hostPath:
                path: ${logcollector-date-dir}
                type: DirectoryOrCreate
    

性能测试数据

日志数据量、采集规则的复杂度以及文件数量等因素都会影响 LogCollector 采集性能。目前日志服务基于 LogCollector 1.0.42 版本进行了性能测试,并获得了相关测试数据。您可以参考如下测试数据及实际情况,调整 LogCollector 资源配置。

说明

如果您使用的 LogCollector 版本低于 1.0.42 版本,请先升级至最新版本。操作步骤请参考升级 LogCollector(宿主机)升级 LogCollector(Kubernetes 集群)

采集模式

文件数量

CPU 配置

内存配置(GB)

采集速率(MB/s)

单行全文模式

1 个文件

1

1

64

2

2

115

3

3

142

5 个文件

1

1

61

2

2

112

3

3

162

JSON 模式

1 个文件

1

1

25

2

2

45

3

3

51

5 个文件

1

1

25

2

2

45

3

3

68

多行全文模式

1 个文件

1

1

38

2

2

56

3

3

60

5 个文件

1

1

38

2

2

60

3

3

86

分隔符模式

1 个文件

1

1

25

2

2

44

3

3

91

5 个文件

1

1

25

2

2

45

3

3

66

单行正则模式

1 个文件

1

1

8

2

2

10

3

3

11

5 个文件

1

1

8

2

2

13

3

3

20

多行正则模式

1 个文件

1

1

12

2

2

16

3

3

16

5 个文件

1

1

12

2

2

22

3

3

34