python遍历二位数组

 

 

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from elasticsearch import Elasticsearch
import os, json, urllib, datetime, shutil
import traceback
import time


gl_es_username = 'remote_monitoring_user'
gl_es_passwd = "elastic"
gl_url = 'http://192.168.1.134:19200'

def get_index_stats():
    es = Elasticsearch([gl_url],http_auth=(gl_es_username, gl_es_passwd))
    try:
        # 获取主节点ip
        cluster_state = es.cluster.state()
        master_node_id = cluster_state['master_node']
        master_node_info = es.nodes.info(node_id=master_node_id)

        # 获取所有索引的名称
        response = es.cat.indices(format='json')
        out_dict = {}
        inner_dict = {}

        for i in range(len(response)):
            index_name = response[i]["index"]
            rep = response[i]["rep"]
            health = response[i]["health"]
            inner_dict["rep"] = rep
            inner_dict["health"] = health
            out_dict[index_name] = inner_dict

        for key in out_dict:
            index_name = key
            print(index_name)
            print(out_dict[index_name]["rep"])
            print(out_dict[index_name]["health"])
    except Exception as e:
        print(e)

if __name__ == '__main__':
    get_index_stats()

 

posted @ 2025-06-09 11:11  slnngk  阅读(5)  评论(0)    收藏  举报