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

时间:2018-03-15 17:10:53

标签: 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"
      }
    }

1 个答案:

答案 0 :(得分:1)

How can I parse custom Metricbeat dictionary for Kibana?中找到解决方案 需要将 fields_under_root 选项设置为 true