如何获取 elticsearch 集群中当前打开的分片数? [英] How to get number of current open shards in elsticsearch cluster?

查看:46
本文介绍了如何获取 elticsearch 集群中当前打开的分片数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在哪里可以获取当前打开的分片数量.我想进行监控以避免这样的情况:

I can't find where to get the number of current open shards. I want to make monitoring to avoid cases like this:

this cluster currently has [999]/[1000] maximum shards open

我可以获得最大限制 - max_shards_per_node

I can get maximum limit - max_shards_per_node

$ curl -X GET "${ELK_HOST}/_cluster/settings?include_defaults=true&flat_settings=true&pretty" 2>/dev/null | grep cluster.max_shards_per_node
"cluster.max_shards_per_node" : "1000",
$

但是不知道如何获取当前打开的分片数(999).

But can't find out how to get number of the current open shards (999).

推荐答案

获取此信息的一个非常简单的方法是调用 _cat/shards API 并使用 wc shell 命令计算行数:

A very simple way to get this information is to call the _cat/shards API and count the number of lines using the wc shell command:

curl -s -XGET ${ELK_HOST}/_cat/shards | wc -l

这将产生一个代表集群中分片数量的数字.

That will yield a single number that represents the number of shards in your cluster.

另一种选择是使用 JSON 格式检索集群统计信息,将结果通过管道传输到 jq 中,然后获取您想要的任何内容,例如下面我正在计算所有 STARTED 分片:

Another option is to retrieve the cluster stats using JSON format, pipe the results into jq and then grab whatever you want, e.g. below I'm counting all STARTED shards:

curl -s -XGET ${ELK_HOST}/_cat/shards?format=json | jq ".[].state" | grep "STARTED" | wc -l

另一种选择是查询_cluster/stats API:

Yet another option is to query the _cluster/stats API:

curl -s -XGET ${ELK_HOST}/_cluster/stats?filter_path=indices.shards.total

这将返回一个带有分片计数的 JSON

That will return a JSON with the shard count

{
  "indices" : {
    "shards" : {
      "total" : 302
    }
  }
}

据我所知,ES 从任何带有单个数字的 API 中吐出的数字是不存在的.为了确定这一点,让我们看看源代码.

To my knowledge there is no single number that ES spits out from any API with the single number. To be sure of that, let's look at the source code.

  1. 错误是从IndicesService.java

要查看如何计算 currentOpenShards,我们可以转到 Metadata.java.

To see how currentOpenShards is computed, we can then go to Metadata.java.

如您所见,代码正在迭代从集群状态检索的索引元数据,非常类似于运行以下命令并计算分片数量,但仅适用于带有 "state" 的索引:打开"

As you can see, the code is iterating over the index metadata that is retrieved from the cluster state, pretty much like running the following command and count the number of shards, but only for indices with "state" : "open"

GET _cluster/state?filter_path=metadata.indices.*.settings.index.number_of*,metadata.indices.*.state

根据该证据,我们几乎可以确定您要查找的单个数字无处可寻,但需要通过我上面展示的方法之一进行计算.如果需要,您可以自由打开功能请求.

From that evidence, we can pretty much be sure that the single number you're looking for is nowhere to be found, but needs to be computed by one of the methods I showed above. You're free to open a feature request if needed.

这篇关于如何获取 elticsearch 集群中当前打开的分片数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆