2

I'm using elasticsearch REST API to add some data to be used in kibana dashboard. I have time stamps in this format 2015-08-04 10:13:14. This format seems to be incompatible with kibana.

Is there any way to convert it to something like logstash timestamps (2015-08-04T10:13:14.000Z) or any other solution to get kibana work on this?

mHxDave
  • 55
  • 7
  • Are the input timestamps in Zulu (UTC, GMT) time? Or are they in a local time? Your required output suggests that they're in Zulu time already, which greatly simplifies life — a simple textual transform is all that's necessary. Kibana seems to be a trifle fussy, though. – Jonathan Leffler Aug 04 '15 at 06:26

2 Answers2

7

you can get the exact miliseconds by using:

timestamp=`date +"%Y-%m-%dT%T.%3N"`

As seen in Linux command to get time in milliseconds:

  • date +"%T.%N" returns the current time with nanoseconds.

  • date +"%T.%6N" returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds.

  • date +"%T.%3N" returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.

Community
  • 1
  • 1
c33s
  • 2,612
  • 1
  • 30
  • 43
0

Replace with bash one whitespace by T and append .000Z:

a="2015-08-04 10:13:14"
b="${a/ /T}.000Z"
echo "$b"

Output:

2015-08-04T10:13:14.000Z
Cyrus
  • 84,225
  • 14
  • 89
  • 153