65 lines
2.2 KiB
Python
Executable File
65 lines
2.2 KiB
Python
Executable File
import rados, sys, json
|
|
|
|
def send_mon_command(cluster, cmd_raw):
|
|
cmd = json.dumps(cmd_raw)
|
|
|
|
# print("get cme {}".format(cmd))
|
|
# print("==================")
|
|
|
|
ret, buf, err = cluster.mon_command(cmd, b'')
|
|
|
|
if(ret == 0):
|
|
json_rst = json.loads(buf)
|
|
# print(json_rst)
|
|
return json_rst
|
|
else:
|
|
print("err {} with msg: {}".format(ret ,err))
|
|
return 0
|
|
|
|
def get_ceph_cluster_status():
|
|
cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
|
|
cluster.connect()
|
|
|
|
status = send_mon_command(cluster, {'prefix': 'status', 'format': 'json'})
|
|
status['health'] = send_mon_command(cluster, {'prefix': 'health', 'detail': 'detail', 'format': 'json'})
|
|
# print('monmap' in status and 'mons' in status['monmap'])
|
|
if not ('monmap' in status and 'mons' in status['monmap']):
|
|
status['monmap'] = send_mon_command(cluster, {'prefix': 'mon dump', 'format': 'json'})
|
|
status['mgrmap'] = send_mon_command(cluster, {'prefix': 'mgr dump', 'format': 'json'})
|
|
|
|
return status
|
|
|
|
def main():
|
|
cluster = rados.Rados(conffile='/etc/ceph/ceph.conf')
|
|
print("\nlibrados version: {}".format(str(cluster.version())))
|
|
print("Will attempt to connect to: {}".format(str(cluster.conf_get('mon host'))))
|
|
|
|
cluster.connect()
|
|
print("Cluster ID: {}".format(cluster.get_fsid()))
|
|
print("Cluster health: {}".format(str(cluster.conf_get('health'))))
|
|
|
|
print("Cluster Statistics")
|
|
print("==================")
|
|
cluster_stats = cluster.get_cluster_stats()
|
|
|
|
for key, value in cluster_stats.items():
|
|
print(key, value)
|
|
|
|
status = get_ceph_cluster_status()
|
|
|
|
rst = {"data": ""}
|
|
rst['data'] = status;
|
|
print("\nSTATUS")
|
|
print("==================")
|
|
print(json.dumps(rst))
|
|
|
|
# status = json.loads(buf)
|
|
# print( '========= health =========' )
|
|
# print (status['health'])
|
|
# print( '========= monmap =========' )
|
|
# print (status['monmap'])
|
|
# print( '========= mgrmap =========' )
|
|
# print (status['mgrmap'])
|
|
|
|
main()
|