Add a time field in elasticsearch and calculate time between two event

I’m new to Grafana.

I’m working with log files stored in Elasticsearch, that contains information about some operations on differents levels, I have a field timestamp that represents the time when each operation has occured on each step.

I want to calculate the time between the start and the end of the process. between step1 and step 3 and add it to a field that I will create so I can visualize it on Grafana.

This is an exemple of some of my logs.

{“log_level”:“INFO”,“timestamp”:“2021-12-22T11:49:06.124890Z”,“event_type”:“step1”,“mid”:“96712abc”}{“log_level”:“INFO”,“timestamp”:“2021-12-22T11:49:07.124890Z”,“event_type”:“step2”,“mid”:“96712abc”} {“log_level”:“INFO”,“timestamp”:“2021-12-22T11:49:08.124890Z”,“event_type”:“step3”,“mid”:“96712abc”}

@abdel989 I’m not sure if you can do this in grafana, you could try the group by transformation if you have a consistent property in your logs that you can group by (is mid an event ID)? Then you might be able to use the difference calculation to find the difference between the first and last timestamp - you may have to play with formatting to get the result you want.

If you’re using logstash to ingest your logs there is a processor that you can use to add fields to your log events based on certain rules. Then you could visualize those fields in grafana. The elapsed filter calculates the time between two events.

1 Like

Hello @melori.arellano, thanks for your help.
I already use logstash, so I used a filter with conditions based on events and I added new field to the logs to store the processing time.
I will read this documentation to know more about functions in grafana, thank you so much ma’am

1 Like

maybe this

image

image

2 Likes