将自定义字段添加到 metricbeat 中 JSON 的源

Add custom fields to source of the JSON in metricbeat

我知道我们可以在 metricbeat.yml 文件中添加自定义字段,

fields:
  customfield1: value1
  customfield2: value2

然后 JSON 输出将生成为,

{
  "@timestamp": "2018-03-15T17:00:04.392Z",
  "@metadata": {
    "beat": "metricbeat",
    "type": "doc",
    "version": "6.2.2"
  },
  "metricset": {
    "rtt": 801,
    "name": "status",
    "module": "kibana",
    "host": "localhost:5601"
  },
  "error": {
    "message": "error making http request: Get http://localhost:5601/api/status: dial tcp [::1]:5601: getsockopt: connection refused"
  },
  "fields": {
    "customfield1": "value1",
    "customfield2": "value2"
  },
  "beat": {
    "name": "TheNameOfBeat",
    "hostname": "localhost",
    "version": "6.2.2"
  }
}

但我想将自定义字段添加到 JSON 消息的源中,而不是在 "fields" 对象中。这可能吗?

有点像,

{
      "@timestamp": "2018-03-15T17:00:04.392Z",
      "customfield1": "value1",
      "customfield2": "value2",
      "@metadata": {
        "beat": "metricbeat",
        "type": "doc",
        "version": "6.2.2"
      },
      "metricset": {
        "rtt": 801,
        "name": "status",
        "module": "kibana",
        "host": "localhost:5601"
      },
      "error": {
        "message": "error making http request: Get http://localhost:5601/api/status: dial tcp [::1]:5601: getsockopt: connection refused"
      },
      "beat": {
        "name": "TheNameOfBeat",
        "hostname": "localhost",
        "version": "6.2.2"
      }
    }

中找到了解决方案 需要将 fields_under_root 选项设置为 true.