如何获取elsticsearch集群中当前打开的分片数量? [英] How to get number of current open shards in elsticsearch cluster?
问题描述
我找不到从哪里获得当前打开的分片的数量.我想进行监视以避免此类情况:
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).
推荐答案
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.
-
从要查看如何计算
currentOpenShards
,我们可以转到To see how
currentOpenShards
is computed, we can then go toMetadata.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.
这篇关于如何获取elsticsearch集群中当前打开的分片数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!