Unlike Filebeat, Metricbeat uses UTC timestamp in @timestamp field and local date in _index. That causes the records to go into the wrong index with Elasticsearch output.
I use version 5.0.2 for ElasticSearch, Filebeat and Metricbeat.
The data is written directly into ElasticSearch.
I solved the problem by configuring the following ElasticSearch pipeline for Metricbeat, that extracts the date part from the original Metricbeat UTC timestamp:
I spent some time grepping through beats code but could not find where it sets _index field. I did find where they set all other fields though, including @timestamp.
So, I suspect _index is set in ElasticSearch. Someone with ElasticSearch internals knowledge would be able to confirm that.
Do I understand this correctly, that Metricbeat publishes @timestamp without the timezone designator, so that ElasticSearch treats it as a timestamp in its local timezone?
No, the @timezone value sent in the event is always in UTC (for all Beats).
The problem requires a bit a knowledge of how Go stores time values. A Go time.Time object holds both a time and a timezone. So when we run a date formatter on the time object to create the index name string (e.g. metricbeat-2017.06.28) it uses the timezone that's internal to the time object as part of the formatting. When you create a new time.Time object using time.Now() the timezone defaults to the host machine's timezone.
In order to fix the issue we need to convert the timezone of the time.Time object to UTC before passing it to the date formatter. This is done using time.UTC() method.
Some of the Beats may already do this when they construct the event, but there is no guarantee (probably Filebeat already does this). But we want to ensure that all time.Time objects contained in events are in UTC. All events published by a Beat pass through a normalization phase in libbeat to fix types, drop nulls, etc. This would be a good place to convert a time values to UTC. That code is here.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.