5

我有以下类型的 json 与我一起使用 filebeat 转储到弹性搜索中{"@timestamp":"2017-02-10T06:30:51.424Z","beat":{"hostname":"myhostname","name":"mydevice-logger","version":"5.2.0"},"fields":{"device_type":"mydevice","env":"staging"},"metricset":{"module":"system","name":"cpu","rtt":211},"system":{"cpu":{"cores":4,"idle":{"pct":0.000000},"iowait":{"pct":0.000000},"irq":{"pct":0.000000},"nice":{"pct":0.000000},"softirq":{"pct":0.000000},"steal":{"pct":0.000000},"system":{"pct":0.000000},"user":{"pct":0.000000}}},"tags":["automata","box"],"type":"metricbeat-test-log"}

我的 logstash(5.1.1 版)配置包含、输入、过滤和输出,如下所示 -

input { 
  beats {
        port => 5046
        codec => json
  }
}

filter {
    if ...{}
    else if [type] == "metricbeat-test-log" {

      date {
        match => ["@timestamp", "ISO8601"]
      }

      }
    }

}


output {
    if ...{}
    else if [type] == "metricbeat-test-log" {
        stdout { codec => rubydebug   }
    }
} 

类型正确,但日期过滤器不起作用。@timestampfinally 总是采用当前时间戳。我想用@timestampjson 中的原始存在替换它。

4

2 回答 2

0

您应该在日期过滤器中使用目标设置:

来自https://www.elastic.co/guide/en/logstash/5.1/plugins-filters-date.html#plugins-filters-date-target

目标

值类型是字符串

默认值为“@timestamp”

将匹配的时间戳存储到给定的目标字段中。如果未提供,则默认更新事件的 @timestamp 字段。

于 2017-02-14T16:04:09.247 回答
0

我在这个旧线程https://discuss.elastic.co/t/replace-timestamp-with-actual-timestamp-from-log-file/72017得到了答案,它解释了"@timestamp":"2017-02-10T06:30:51.424Z"上面的日志行是 JSON 表示@timestamp 字段及其值。按照建议,我在 filebeat 中添加了 json 配置,它对我有用。

- input_type: log
  paths:
    - /var/logs/mylogs/*.log
  fields:
    environment: testing
  document_type: test-metric-document

  json.keys_under_root: true   # added this line 
  json.overwrite_keys: true    # added this line 

虽然我对这个解决方案不满意,因为我真正需要的是同时获取时间戳、logstash 事件一个(在其他变量中)和来自@timestamp 的登录时间戳。

于 2017-02-16T06:26:17.327 回答