我正在创建一个lambda函数,它将包含一个python脚本。lambda函数的作用是如果集群中的分片使用率超过90%,即使用了4500/5000个分片,则发出警报。我使用的是python的ElasticSearch客户端,所以我想知道是否有任何方法可以让您计算开放分片的容量。提前感谢
发布于 2021-04-11 17:34:02
您可以使用此Elasticsearch library并运行以下内容:
es = Elasticsearch()
stats = es.cluster.stats()
shards = stats['indices']['shards']['total']它使用此stats method来获取集群的统计数据,从那里您可以获取所有索引上的分片数量所需的所有信息。
如果您想要计算分片的最大阈值并根据使用率的某个百分比进行通知,请找到您的最大分片数/节点,从stats获取节点数,计算最大阈值,并检查是否需要使用类似于该notify = shards/max > 0.9的内容进行通知。
编辑:
下面是一个更完整的代码示例:
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 notificationhttps://stackoverflow.com/questions/67025760
复制相似问题