How to get average number of samples for time series data with DSL query?

I want to get the average number of request per second(or minute) for performance testing data, but the basic aggregation possibilities i've found so far doesn't cover this.

I could only do a count on a field, but that only gives me the total number of requests/documents. For my problem what required is putting document in bucket on time period base and the do an average on them. Probably nesting 2 aggregations, like this:

"aggs": {
  "sample_rate_per_second": {
    "date_histogram": {
      "field": "date",
      "fixed_interval": "1s"
    }
  }
}

and this

"aggs": {
  "avg_sample_rate": { "avg": { "field": "fieldname" } }
}

Can you please help me out how to do it?

This is the query i've got so far:

GET jmeter-result/_search
{
  "query": {
    "bool": {
      "filter": {
        "term":  { "test_run_id": "somerunid" }
      },
      "must": {
        "query_string": {
          "query": "somethreadname",
          "default_field": "ThreadName"
        }
      }
    }
  },
  "aggs": {
    "percentiles": {
      "percentiles": {
        "field": "ResponseTime" 
      }
    },
    "total_requests": {
      "value_count": {
        "field" : "ResponseCode.keyword"
      }
    },
    "allowed_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "ALLOWED"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    },
    "denied_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "DENIED"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    },
    "failed_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "FAILURE"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    }
  }
}

And this is how a document looks like:

{
    "_index": "jmeter-result",
    "_type": "_doc",
    "_id": "RhYwFYMBeBBV0OlLtsCK",
    "_score": 1,
    "_source": {
        "test_run_id": "run112",
        "ResponseCode": "ALLOWED",
        "component.name": "componentname",
        "IdleTime": 0,
        "ErrorCount": 0,
        "Timestamp": "2022-09-07T01:44:17.239+0200",
        "Latency": 9,
        "Bytes": 114,
        "SentBytes": 0,
        "job_name": "elasticfieldjobname",
        "BodySize": 114,
        "TestElement.name": "Thread-6",
        "ThreadName": "jp@gc - Ultimate Thread Group - First 1-1",
        "ResponseTime": 501,
        "FailureMessage": "",
        "test_plan_name": "testplanname",
        "SampleLabel": "jp@gc - Dummy Sampler",
        "test_case": "elasticfieldtestcase"
    },
    "fields": {
        "test_case.keyword": [
            "elasticfieldtestcase"
        ],
        "ThreadName.keyword": [
            "jp@gc - Ultimate Thread Group - First 1-1"
        ],
        "IdleTime": [
            0
        ],
        "ErrorCount": [
            0
        ],
        "Timestamp": [
            "2022-09-06T23:44:17.239Z"
        ],
        "Bytes": [
            114
        ],
        "component.name.keyword": [
            "raz"
        ],
        "SentBytes": [
            0
        ],
        "TestElement.name": [
            "Thread-6"
        ],
        "FailureMessage.keyword": [
            ""
        ],
        "ResponseTime": [
            501
        ],
        "FailureMessage": [
            ""
        ],
        "test_plan_name": [
            "testplanname"
        ],
        "test_case": [
            "elasticfieldtestcase"
        ],
        "test_run_id": [
            "run112"
        ],
        "test_run_id.keyword": [
            "run112"
        ],
        "ResponseCode": [
            "ALLOWED"
        ],
        "component.name": [
            "raz"
        ],
        "TestElement.name.keyword": [
            "Thread-6"
        ],
        "ResponseCode.keyword": [
            "ALLOWED"
        ],
        "Latency": [
            9
        ],
        "job_name": [
            "elasticfieldjobname"
        ],
        "job_name.keyword": [
            "elasticfieldjobname"
        ],
        "BodySize": [
            114
        ],
        "ThreadName": [
            "jp@gc - Ultimate Thread Group - First 1-1"
        ],
        "SampleLabel.keyword": [
            "jp@gc - Dummy Sampler"
        ],
        "SampleLabel": [
            "jp@gc - Dummy Sampler"
        ],
        "test_plan_name.keyword": [
            "testplanname"
        ]
    }
}

Thank you!

{
  "track_total_hits": true,
  "aggs": {
    "LabelA": {
      "date_histogram": {
        "field": "Timestamp",
        "interval": "hour"
      },
      "aggs": {
        "LabelB": {
          "value_count": {
            "field": "Timestamp"
          }
        }
      }
    },
    "average": {
      "avg_bucket": {
        "buckets_path": "LabelA>LabelB"
      } 
    }
  },
  "size": 0
}
1 Like

Thanks linkerc!

If anyone interested, this is the final form of the query:

GET jmeter-result-tmpl/_search
{
  "query": {
    "bool": {
      "filter": {
        "term":  { "test_run_id": "testrunid" }
      },
      "must": {
        "query_string": {
          "query": "somethreadname",
          "default_field": "ThreadName"
        }
      }
    }
  },
  "track_total_hits": true,
  "size": 0,
  "aggs": {
    "percentiles": {
      "percentiles": {
        "field": "ResponseTime" 
      }
    },
    "total_requests": {
      "value_count": {
        "field" : "ResponseCode.keyword"
      }
    },
    "sample_rate_per_second_buckets": {
      "date_histogram": {
        "field": "Timestamp",
        "fixed_interval": "1s"
      },
      "aggs": {
        "samples_per_bucket": {
          "value_count": {
            "field": "Timestamp"
          }
        }
      }
    },
    "average_request_per_second": {
      "avg_bucket": {
        "buckets_path": "sample_rate_per_second_buckets>samples_per_bucket"
      } 
    },
    "allowed_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "ALLOWED"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    },
    "denied_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "DENIED"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    },
    "failed_requests": {
      "filter": {
        "term": {
          "ResponseCode.keyword": "FAILURE"
        }
      },"aggs": {
        "count": {
          "value_count": {
            "field": "ResponseCode.keyword"
          }
        }
      }
    }
  }
}

I wonder if it is possible to disable detailed response for a specific aggregation? Like for sample_rate_per_second_buckets in this example . If it is a long running test or the fixed_interval is set to 1s, then the response is very long with all the buckets and i only need to see the calculated avg from those.

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