Reputation: 23
I'm using Kibana to show the statuses of multiple microservices based on the most up to date value for each. I would like to replace the April 8th 2019, 14:37:13.173 format with somethine like 2 minutes ago or 2 minutes 21seconds ago. I know I can filter for the last 15minutes for the Kibana data entries, but that doesn't show how long ago each services was updated.
I've tried going into the Index Patterns and changing the date pattern, but it doesn't take functions, but only the formatting. I could add another field that would be sent every minute, but that is just wasting ressources and complicating everything.
Upvotes: 0
Views: 260
Reputation: 23
I was able to solve the problem once I knew that Scripted Fields existed so this is what I used to show how long ago the update was :
if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>7200){
return Math.round((new Date().getTime()-doc['@timestamp'].value)/3600000) + " hours ago";
}else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>3600){
return Math.round((new Date().getTime()-doc['@timestamp'].value)/3600000) + " hour ago";
}else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>120){
return Math.round((new Date().getTime()-doc['@timestamp'].value)/60000) + " minutes ago";
} else if(Math.round((new Date().getTime()-doc['@timestamp'].value)/1000)>60){
return Math.round((new Date().getTime()-doc['@timestamp'].value)/60000) + " minute ago";
}else {
return Math.round((new Date().getTime()-doc['@timestamp'].value)/1000) + " seconds ago";
}
Upvotes: 0