From 4a8360f2af2f61d940424442385142965e1af1d3 Mon Sep 17 00:00:00 2001 From: Chenyang Ji Date: Thu, 6 Jun 2024 13:52:20 -0700 Subject: [PATCH] Add document for top n queries by cpu and memory Signed-off-by: Chenyang Ji --- .../query-insights/top-n-queries.md | 77 +++++++++++++++++-- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/_observing-your-data/query-insights/top-n-queries.md b/_observing-your-data/query-insights/top-n-queries.md index 44469fa64b..29abe58478 100644 --- a/_observing-your-data/query-insights/top-n-queries.md +++ b/_observing-your-data/query-insights/top-n-queries.md @@ -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} @@ -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. ```json PUT _cluster/settings @@ -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 +```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 @@ -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: +```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" : { @@ -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: +```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: @@ -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 %} \ No newline at end of file