Filebeat 添加不需要的空白字段

Filebeat adds unwanted blank fields

我的目标是使用 Filebeat 从不同的服务器收集日志,并 aggregate/visualize 使用 ElasticSearch 和 Kibana。目前,我将 Logstash 排除在外。

到目前为止,我已经能够配置 Filebeat 实时推送日志,并且我能够通过 Kibana 界面确认日志确实被推送到 ElasticSearch。


问题:

问题是 Filebeat(或 ElasticSearch)会自动向索引添加额外的空 fields/properties。

我在Kibana界面上看到的一些字段:

aws.cloudtrail.user_identity.session_context.creation_date
azure.auditlogs.properties.activity_datetime
azure.enqueued_time
azure.signinlogs.properties.created_at
cef.extensions.agentReceiptTime
cef.extensions.deviceCustomDate1
cef.extensions.deviceCustomDate2
cef.extensions.deviceReceiptTime
cef.extensions.endTime
cef.extensions.fileCreateTime
cef.extensions.fileModificationTime
cef.extensions.flexDate1
...

都是空字段。

当我使用 GET /[index]/_mapping 检查该索引的映射时,我可以看到大约 3000 个我没有真正添加的字段。我不确定这些字段是如何添加的以及如何删除它们。


复制:

Filebeat 和 ElasticSearch docker 我使用的图像:

elasticsearch:7.8.0
elastic/filebeat:7.8.0

在基本映像之上,我将基本配置文件简单地放置为:

# filebeat.yml

filebeat.inputs:
- type: log
  paths:
    - /path_to/my_log_file/metrics.log

output.elasticsearch:
  hosts: ["http://192.168.0.1:9200"]
# elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0

node.name: node-1

discovery.seed_hosts: ["127.0.0.1"]

cluster.initial_master_nodes: ["node-1"]

典型的日志消息如下所示:

2020-07-01 08:40:07,432 - CPUUtilization.Percent:50.0|#Level:Host|#hostname:a78f2ab3da65,timestamp:1593592807
2020-07-01 08:40:07,437 - DiskAvailable.Gigabytes:43.607460021972656|#Level:Host|#hostname:a78f2ab3da65,timestamp:1593592807

谢谢

输入Elastic Common Schema (ECS), a godsend!

当 Filebeat 启动时,它会安装一个索引模板,其中包含通用模式中的所有 ECS 字段,这就是您在索引映射中看到这么多字段的原因,但这并不是真正的问题。

然后,在 Kibana 界面上,您会在 Table 视图(“发现”选项卡)中看到所有这些“空”字段。但是如果切换到 JSON 视图,您会发现这些字段实际上并不在文档中。 Filebeat 不会将它们添加到您的文档中。您在 Table 视图中看到它们的原因是因为 Kibana 正在请求它们(使用 docvalue_fields)。只需单击检查并查看 Kibana 发送到 Elasticsearch 的请求。

所以真的没什么可担心的。

关于您的实际消息,如果您要解析 CPUUtilization.Percent:50.0,您实际上可以将其存储到名为 "system.cpu.total.pct": 50 的标准 ECS 字段中,并且您可以在 Metrics 应用程序中看到这些值随时间演变在基巴纳。 DiskAvailable.Gigabytes:43.607460021972656

也一样

所有输入都由 filebeat 自动映射到 'elastic common schema' 又名 ECS 并导出。请查看here了解更多详情。

如果在filebeat.yml

中定义弹性指数

您可以进入堆栈管理 > 索引管理并编辑 filebeat 索引。 在设置默认字段中:

 "query": {
  "default_field": [
    "message",
    "tags",
    "agent.ephemeral_id",
    "agent.id",
    "agent.name",
    "agent.type",
    ...
    ]}

您可以从这里删除所有不需要的字段。

您可以像这样定义自己的模板:

curl -XPUT 'localhost:9200/_template/filebeat-7.8.0' -H 'Content-Type: application/json' -d'
{
    "order" : 1,
    "index_patterns" : [
      "filebeat-7.8.0-*"
    ],
    "settings" : {
      "index" : {
        "lifecycle" : {
          "name" : "filebeat",
          "rollover_alias" : "filebeat-7.8.0"
        },
        "mapping" : {
          "total_fields" : {
            "limit" : "10000"
          }
        },
        "refresh_interval" : "5s"
      }
    },
    "mappings" : {
      "_meta" : {
        "beat" : "filebeat",
        "version" : "7.8.0"
      },
      "date_detection" : false,
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
    "type": {
      "type": "keyword"
    },
    "namespace": {
      "type": "keyword"
    },
    "app": {
      "type": "keyword"
    },
    "k8s-app": {
      "type": "keyword"
    },
    "node": {
      "type": "keyword"
    },
    "pod": {
      "type": "keyword"
    },
    "stream": {
      "type": "keyword"
    }
      }
    },
    "aliases" : { }
  }'

解释:

正如@Val 所解释的那样,Filebeat 在启动时会安装一个名为 filebeat-7.8.0 的索引模板。但是,如果模板存在,Filebeat 将直接使用它而不是创建一个新模板。 setup.template.overwrite 的默认值为 false (https://www.elastic.co/guide/en/beats/filebeat/current/configuration-template.html)。通过这样做,您的映射中将不会有这些字段,并且 Kibana 也不会显示这些字段。