Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import requests
- r = requests.get('https://dev.myserver.com:9200/_cluster/stats', auth=('admin', 'admin'))
- data = r.json()
- # data = str(data)
- # print("#################")
- # print(type(data))
- # print(data)
- #
- # print("\nStatus :", data['status'])
- # print("Cluster Name :", data['cluster_name'])
- # print("Number of Indices :", data['indices']['count'])
- # print("Number of Shards Total:", data['indices']['shards']['total'])
- # print("Number of Shards Primaries:", data['indices']['shards']['primaries'])
- # print("Number of Shards Replication:", data['indices']['shards']['replication'])
- # print("Number of Docs Total:", data['indices']['docs']['count'])
- # print("Number of Docs Deleted:", data['indices']['docs']['deleted'])
- # print("Store Size:", int(data['indices']['store']['size_in_bytes']) / 1000000, "MB")
- def get_Status():
- try:
- return data['status']
- except:
- return "ERROR : Get Cluster Status"
- def get_StatusAll():
- try:
- return data
- except:
- return "ERROR : Get Cluster Status"
- def get_ClusterName():
- try:
- return data['cluster_name']
- except:
- return "ERROR : Get Cluster Name"
- def get_IndicesCount():
- try:
- return data['indices']['count']
- except:
- return "ERROR : Get Indices Count"
- def get_ShardsTotal():
- try:
- return data['indices']['shards']['total']
- except:
- return "ERROR : Get shards Count"
- def get_ShardsPrimary():
- try:
- return data['indices']['shards']['primaries']
- except:
- return "ERROR : Get shards Count"
- def get_ShardsReplica():
- try:
- return data['indices']['shards']['replication']
- except:
- return "ERROR : Get shards Count"
- def get_DocsCount():
- try:
- return data['indices']['docs']['count']
- except:
- return "ERROR : Get Docs Count"
- def get_DocsDeleted():
- try:
- return data['indices']['docs']['deleted']
- except:
- return "ERROR : Get Docs Count"
- def get_StoreSize():
- try:
- return data['indices']['store']['size_in_bytes']
- except:
- return "ERROR : Get Store Size"
- def get_StoreThrottleTime():
- try:
- return data['indices']['store']['throttle_time_in_millis']
- except:
- return "ERROR : Get Store Throttle time in milis"
- def get_Plugins():
- try:
- plugin_names = data['nodes']['plugins']
- plugin_list=[]
- for plugin_name in plugin_names:
- plugin_list.append(plugin_name['name'].upper())
- plugin_list.sort()
- return ' '.join(plugin_list)
- except:
- return "ERROR : Get Plugins installed"
- def no_Argument():
- print("!ERROR! Use this Script with arguments like : SCRIPT.PY status")
- print("Available arguments : all, status, name, indices, shards_total")
- def main(argv):
- if not argv:
- no_Argument()
- for arg in argv:
- if arg.lower() == 'status':
- print(get_Status().upper())
- exit(1)
- elif arg.lower() == 'all':
- print(get_StatusAll())
- exit(1)
- elif arg.lower() == 'name':
- print(get_ClusterName())
- exit(1)
- elif arg.lower() == 'indices':
- print(get_IndicesCount())
- exit(1)
- elif arg.lower() == 'shards_total':
- print(get_ShardsTotal())
- exit(1)
- elif arg.lower() == 'shards_primary':
- print(get_ShardsPrimary())
- exit(1)
- elif arg.lower() == 'shards_replica':
- print(get_ShardsReplica())
- exit(1)
- elif arg.lower() == 'docs_count':
- print(get_DocsCount())
- exit(1)
- elif arg.lower() == 'docs_deleted':
- print(get_DocsDeleted())
- exit(1)
- elif arg.lower() == 'store_size':
- print(get_StoreSize())
- exit(1)
- elif arg.lower() == 'store_thtime':
- print(get_StoreThrottleTime())
- exit(1)
- elif arg.lower() == 'plugins':
- print(get_Plugins())
- exit(1)
- else:
- no_Argument()
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement