首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取集群中正在使用的分片数量-- Python

如何获取集群中正在使用的分片数量-- Python
EN

Stack Overflow用户
提问于 2021-04-10 01:31:00
回答 1查看 238关注 0票数 0

我正在创建一个lambda函数,它将包含一个python脚本。lambda函数的作用是如果集群中的分片使用率超过90%,即使用了4500/5000个分片,则发出警报。我使用的是python的ElasticSearch客户端,所以我想知道是否有任何方法可以让您计算开放分片的容量。提前感谢

EN

回答 1

Stack Overflow用户

发布于 2021-04-11 17:34:02

您可以使用此Elasticsearch library并运行以下内容:

代码语言:javascript
运行
复制
es = Elasticsearch()
stats = es.cluster.stats()
shards = stats['indices']['shards']['total']

它使用此stats method来获取集群的统计数据,从那里您可以获取所有索引上的分片数量所需的所有信息。

如果您想要计算分片的最大阈值并根据使用率的某个百分比进行通知,请找到您的最大分片数/节点,从stats获取节点数,计算最大阈值,并检查是否需要使用类似于该notify = shards/max > 0.9的内容进行通知。

编辑:

下面是一个更完整的代码示例:

代码语言:javascript
运行
复制
threshold = 0.9
cluster_stats = es.cluster.stats()
cluster_settings = es.cluster.get_settings()
total_shards = cluster_stats['indices']['shards']['total']
data_nodes = cluster_stats['nodes']['count']['data']
max_shards_node = int(cluster_settings['persistent']['cluster']['max_shards_per_node'])
# Calculate if the current amount of shards is approaching the threshold
notify = total_shards/(data_nodes * max_shards_node) > threshold
if notify:
    # you choose how to handle notification
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67025760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档