Calculating indexing rate programmatically

The indices tab in Kibana Monitoring UI shows the indexing rate:

Can anyone guide me on how can I get that programatically using API? Based on this thread as well as this, it seems I can do the following:

GET /.monitoring-es-6-2021.01.20/_search?sort=timestamp:desc&filter_path=**.primaries.indexing&size=2
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "index_stats.index": "my_index"
          }
        }
      ]
    }
  }
}

This will output something like:

{
  "hits" : {
   ...
              "indexing" : {
                "index_total" : 54527554,
                "index_time_in_millis" : 6592199,
                ...
      },
      {
       ...
              "indexing" : {
                "index_total" : 54315000,
                "index_time_in_millis" : 6564685,
                ...
}

I suppose I can calculate the indexing rate as (index_total_1 - index_total_2) / (index_time_in_seconds_1-index_time_in_seconds_2) i.e ( 54527554-54315000)/(6592.199-6564.685) = 7725.30/s

Is this the correct way or a better / shorter way exists?

Thanks.

Yup, this is basically all we do in the UI as well.

We look at the first document in the timespan and look at the last document in the timespan and calculate the rate based on those values in the same fashion as you described

1 Like

Thank you Chris. That helps. Btw,

How would do that? Mind sharing? I mean how do you get the last document in the timespan? You use a specific size?

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