首页 > 解决方案 > 来自 Kubernetes 的 Filebeat 和 json 日志不起作用

问题描述

我已经使用带有 Elasticsearch 和 Kibana 6.8.6 以及 Filebeat 7.5.1 的 minikube 设置了一个示例 Kubernetes 集群。

我的应用程序以 json 格式生成日志消息 {"@timestamp":"2019-12-30T21:59:48+0000","message":"example","data":"data-462"}

我可以在 Kibana 中看到日志消息,但我的 json 日志作为字符串嵌入在“消息”属性中:

在此处输入图像描述

我配置json.keys_under_root: true无效(如文档中所述:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#filebeat-input-log-config-json

我的配置:

  filebeat.yml: |-
    migration.6_to_7.enabled: true

    filebeat.config:
      modules:
        path: ${path.config}/modules.d/*.yml
        reload.enabled: false

    filebeat.autodiscover:
      providers:
        - type: kubernetes
          hints.enabled: true
          hints.default_config.enabled: false
          json.keys_under_root: true
          json.add_error_key: true

    output.elasticsearch:
      hosts: ['${ELASTICSEARCH_HOST:elasticsearch}:${ELASTICSEARCH_PORT:9200}']
      username: ${ELASTICSEARCH_USERNAME}
      password: ${ELASTICSEARCH_PASSWORD}
  kubernetes.yml: |-
    - type: docker
      containers.ids:
      - "*"
      processors:
        - add_kubernetes_metadata:
            in_cluster: true

我需要将“消息”和“数据”字段作为 Kibana 中的单独字段。

我错过了什么?

标签: jsonkubernetesminikubefilebeat

解决方案


尝试添加json.message_key: message您的 filebeat 配置


推荐阅读