Skip to content

Commit

Permalink
Add document for top n queries by cpu and memory
Browse files Browse the repository at this point in the history
Signed-off-by: Chenyang Ji <[email protected]>
  • Loading branch information
ansjcy committed Jun 6, 2024
1 parent 6e2f1d4 commit 4a8360f
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions _observing-your-data/query-insights/top-n-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ Monitoring the top N queries in query insights features can help you gain real-t

To enable monitoring of the top N queries, configure the following [dynamic settings]({{site.url}}{{site.baseurl}}/install-and-configure/configuring-opensearch/index/#dynamic-settings):

- `search.insights.top_queries.latency.enabled`: Set to `true` to [enable monitoring of the top N queries](#enabling-the-top-n-queries-feature).
- `search.insights.top_queries.latency.window_size`: [Configure the window size](#configuring-window-size).
- `search.insights.top_queries.latency.top_n_size`: [Specify the value of n](#configuring-the-value-of-n).
- `search.insights.top_queries.latency.enabled`: Set to `true` to [enable monitoring of the top N queries by latency](#enabling-the-top-n-queries-feature).
- `search.insights.top_queries.latency.window_size`: [Configure the window size for top n queries by latency](#configuring-window-size).
- `search.insights.top_queries.latency.top_n_size`: [Specify the value of n for top n queries by latency](#configuring-the-value-of-n).
- `search.insights.top_queries.cpu.enabled`: Set to `true` to [enable monitoring of the top N queries by cpu usage](#enabling-the-top-n-queries-feature).
- `search.insights.top_queries.cpu.window_size`: [Configure the window size for top n queries by cpu usage](#configuring-window-size).
- `search.insights.top_queries.cpu.top_n_size`: [Specify the value of n for top n queries by cpu usage](#configuring-the-value-of-n).
- `search.insights.top_queries.memory.enabled`: Set to `true` to [enable monitoring of the top N queries for top n queries by memory usage](#enabling-the-top-n-queries-feature).
- `search.insights.top_queries.memory.window_size`: [Configure the window size for top n queries by memory usage](#configuring-window-size).
- `search.insights.top_queries.memory.top_n_size`: [Specify the value of n for top n queries by memory usage](#configuring-the-value-of-n).

It's important to exercise caution when enabling this feature because it can consume system resources.
{: .important}
Expand All @@ -25,7 +31,7 @@ For detailed information about enabling and configuring this feature, see the fo

## Enabling the top N queries feature

After installing the `query-insights` plugin, you can enable the top N queries feature (which is disabled by default) by using the following dynamic setting. This setting enables the corresponding collectors and aggregators in the running cluster:
After installing the `query-insights` plugin, you can enable the top N queries feature (which is disabled by default) by using the following dynamic setting. This setting enables the corresponding collectors and aggregators in the running cluster. For example, the below command enables top n queries by latency.

Check warning on line 34 in _observing-your-data/query-insights/top-n-queries.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.DirectionAboveBelow] Use 'following or later' instead of 'below' for versions or orientation within a document. Use 'above' and 'below' only for physical space or screen descriptions. Raw Output: {"message": "[OpenSearch.DirectionAboveBelow] Use 'following or later' instead of 'below' for versions or orientation within a document. Use 'above' and 'below' only for physical space or screen descriptions.", "location": {"path": "_observing-your-data/query-insights/top-n-queries.md", "range": {"start": {"line": 34, "column": 266}}}, "severity": "WARNING"}

```json
PUT _cluster/settings
Expand All @@ -37,9 +43,27 @@ PUT _cluster/settings
```
{% include copy-curl.html %}

Other available metrics are cpu usage and memory usage. You can enable them with

Check failure on line 46 in _observing-your-data/query-insights/top-n-queries.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_observing-your-data/query-insights/top-n-queries.md", "range": {"start": {"line": 46, "column": 29}}}, "severity": "ERROR"}
```json
PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.cpu.enabled" : true
}
}

PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.memory.enabled" : true
}
}
```
{% include copy-curl.html %}

## Configuring window size

You can configure the window size for the top N queries by latency with `search.insights.top_queries.latency.window_size`. For example, a cluster with the following configuration will collect top N queries in a 60-minute window:
You can configure the window size for the top N queries by latency with `search.insights.top_queries.latency.window_size`. For example, a cluster with the following configuration will collect top N queries by latency in a 60-minute window:

```json
PUT _cluster/settings
Expand All @@ -51,11 +75,29 @@ PUT _cluster/settings
```
{% include copy-curl.html %}

Other available metrics are cpu usage and memory usage. You can configure the window size to 60 minutes for these metrics by:

Check failure on line 78 in _observing-your-data/query-insights/top-n-queries.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_observing-your-data/query-insights/top-n-queries.md", "range": {"start": {"line": 78, "column": 29}}}, "severity": "ERROR"}
```json
PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.cpu.window_size" : "60m"
}
}

PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.memory.window_size" : "60m"
}
}
```
{% include copy-curl.html %}

## Configuring the value of N

You can configure the value of N in the `search.insights.top_queries.latency.top_n_size` parameter. For example, a cluster with the following configuration will collect the top 10 queries in the specified window size:

```
```json
PUT _cluster/settings
{
"persistent" : {
Expand All @@ -65,6 +107,25 @@ PUT _cluster/settings
```
{% include copy-curl.html %}


Other available metrics are cpu usage and memory usage. You can configure the top n size to 10 for these metrics by:

Check failure on line 111 in _observing-your-data/query-insights/top-n-queries.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: cpu. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_observing-your-data/query-insights/top-n-queries.md", "range": {"start": {"line": 111, "column": 29}}}, "severity": "ERROR"}
```json
PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.cpu.top_n_size" : 10
}
}

PUT _cluster/settings
{
"persistent" : {
"search.insights.top_queries.memory.top_n_size" : 10
}
}
```
{% include copy-curl.html %}

## Monitoring the top N queries

You can use the Insights API endpoint to obtain top N queries by latency:
Expand All @@ -74,9 +135,11 @@ GET /_insights/top_queries
```
{% include copy-curl.html %}

Specify a metric type to filter the response by metric type (latency is the only supported type as of 2.12):
Specify a metric type to filter the response by metric type:

```json
GET /_insights/top_queries?type=latency
GET /_insights/top_queries?type=cpu
GET /_insights/top_queries?type=memory
```
{% include copy-curl.html %}

0 comments on commit 4a8360f

Please sign in to comment.