# How to define metric's @timestamp from Data collection side(which is beat side)?

**URL:** <https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500>\
**Category:** Logstash\
**Created:** [September 14, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500 "2017-09-14T09:36:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_guo/32/42297_2.png) [@Robin\_Guo](https://discuss.elastic.co/u/Robin_Guo)\
**Post date:** [September 14, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500/1 "2017-09-14T09:36:40Z")

</div>

Dear folks,

Recently I've been working on customizing beat with bash to generate the json data that logstash needed instead of to write own beat with go.

* * *

Cuz I'm not the go expert. I'm good to implement customizing beat with script.  
I didn't add field @timestamp for original json raw data gernated from script,after the json raw data sent to logstash, logstash addes some metadata to this raw json data (like **@version ,@timestamp** ).

* * *

The problem is that, I want to add the field @timestamp to original json raw data ,not want to let logstash or elasticsearch to add or modify @timestamp.  
otherwise the metrics we collected that script triggered is not precise at that time.

* * *

By the way, how linux "date" command generate the correct the unix timestamp based iso8601?

example:

`"@timestamp": "2017-09-15T03:19:11.610Z"`

(I think this timestamp is Accurate to milliseconds and end up with Three decimal places)

* * *

Any suggestions or comments are grateful?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 18, 2017, 5:33am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500/2 "2017-09-18T05:33:49Z")

</div>

> By the way, how linux "date" command generate the correct the unix timestamp based iso8601?

`date -u +%Y-%m-%dT%H:%M:%SZ` gives you the right format but without the milliseconds. I don't think date(1) supports millisecond resolution.

Generating JSON files using bash doesn't strike me as a great idea. I'd use a real language that gives correct JSON serialization and supports millisecond resolution for timestamps without jumping through hoops.

---

<div class="post-metadata">

**Author:** ![Robin\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_guo/32/42297_2.png) [@Robin\_Guo](https://discuss.elastic.co/u/Robin_Guo)\
**Post date:** [September 21, 2017, 2:42am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500/3 "2017-09-21T02:42:00Z")

</div>

> [@magnusbaeck](#):
>
> ?
> 
> date -u +%Y-%m-%dT%H:%M:%SZ gives you the right format but without the milliseconds. I don't think date(1) supports millisecond resolution.
> 
> Generating JSON files using bash doesn't strike me as a great idea. I'd use a real language that gives correct JSON serialization and supports millisecond resolution for timestamps without jumping through hoops.

@magnusbaeck

Ｔhanks for your prompt reply, you're right.  
but what language would you like to recommend for customizing the metrics with Jason serialization.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 22, 2017, 6:26am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500/4 "2017-09-22T06:26:11Z")

</div>

> but what language would you like to recommend for customizing the metrics with Jason serialization.

Any language that you're comfortable with that can serialize JSON.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 20, 2017, 6:26am UTC](https://discuss.elastic.co/t/how-to-define-metrics-timestamp-from-data-collection-side-which-is-beat-side/100500/5 "2017-10-20T06:26:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
