Search code examples
elasticsearchkibanaelastic-stackelk

Kibana dashboard to show average time difference


I want to create a visualization in Kibana which shows the average response time.

I have these 2 time stamp fields : state_time end_time

I am calculating the average response time as: avg response time = avg (start time - end time).

Can i achieve tis using some formula in Kibana?


Solution

  • The runtime field can help you to achieve this.

    PUT test_kibana_time_diff/_doc/1
    {
      "end_time": "2023-06-06T16:21:15.000Z",
      "start_time": "2023-06-06T15:21:15.000Z"
    }
    

    PUT test_kibana_time_diff/_mapping
    {
      "runtime": {
        "time_diff_minutes": {
          "type": "long",
          "script": {
            "source": "emit((doc['end_time'].value.millis - doc['start_time'].value.millis) / (1000 * 60))"
          }
        }
      }
    }
    

    enter image description here