filebeat.yaml(k8s configmap)部署清单

发布时间 2023-07-20 14:46:50作者: 力王7314
apiVersion: v1
kind: ConfigMap
metadata:
  name: bh-shard-2-filebeat-config
  namespace: bluehelix
  labels:
    app: bh-shard-2-test
    app.kubernetes.io/managed-by: Helm
    chart: java-0.9.9
    heritage: Helm
    release: bluehelix-bh-shard-2
data:
  filebeat.yml: |-
    filebeat.inputs:
    - type: log
      processors:
      # - add_kubernetes_metadata:
          # in_cluster: true
      paths:
        - "/mnt/log/gc.log"
      fields:
        app_name: bh-shard-2
        app: gc
        group: bluehelix
        namespaces: bluehelix
        clusterName: "${CLUSTER_NAME:}"
    - type: log
      processors:
      paths:
        - "/mnt/log/requestlog.log"
      fields: #设置好之后在kibana可以根据fields定义的name过滤和分类
        app_name: bh-shard-2
        app: request
        group: bluehelix
        namespaces: bluehelix
        clusterName: "${CLUSTER_NAME:}"
      close_inactive: 1m
      close_timeout: 3h
      clean_inactive: 72h
      ignore_older: 70h
      exclude_files: ['debug']
      json.message_key: message     #json.xxx这4行的作用主要是解析json字符串,然后可以根据json里面的key进行筛选过滤,作图要用,
      json.keys_under_root: true
      json.overwrite_keys: true
      json.add_error_key: true
    - type: log
      processors:
      paths:
        - "/mnt/log/logstash.log"
      fields: 
        app_name: bh-shard-2
        app: bh-shard-2
        group: bluehelix
        namespaces: bluehelix
        clusterName: "${CLUSTER_NAME:}"
      #没有新日志采集后多长时间关闭文件句柄,默认5分钟,设置成1分钟,加快文件句柄关闭;
      close_inactive: 1m
      #传输了3h后荏没有传输完成的话就强行关闭文件句柄;
      close_timeout: 3h
      #这个配置项也应该配置上,默认值是0表示不清理,不清理的意思是采集过的文件描述在registry文件里永不清理,在运行一段时间后,registry会变大,可能会带来问题。
      clean_inactive: 72h
      #设置了clean_inactive后就需要设置ignore_older,且要保证ignore_older < clean_inactive
      ignore_older: 70h
      #multiline.pattern: ^20[0-9]{2}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}    #multiline.xxx主要是做多行合并的,如果filebeat做多行合并直接插入es,那么kibana在作图标的时候将很不方便,因此,如果filebeat直接插入es建议不合并日志,进行逐条插入es,这样更有利于kibana作图
      #multiline.negate: true
      #multiline.match: after
      # 和福林确认日志只需要处理1毫秒内的多行输出
      #multiline.timeout: 50ms
      # 只保留40行日志
      #multiline.max_lines: 40
      exclude_files: ['debug']
      json.message_key: message
      json.keys_under_root: true
      json.overwrite_keys: true
      json.add_error_key: true
    output.elasticsearch:
      enabled: true
      hosts: ["eck-cluster-es-default.elastic-system.svc.cluster.local:9200"]
      index: "%{[fields.app]}-%{+yyyy.MM.dd}"
    setup.ilm.enabled: false
    setup.template.name: "%{[fields.app]}"
    setup.template.pattern: "%{[fields.app]}-*"
    setup.template.enabled: false
    setup.template.overwrite: true