Skip to content

Instantly share code, notes, and snippets.

@wido
Last active June 16, 2020 07:42
Show Gist options
  • Save wido/ac53ae01d661dd57f4a8 to your computer and use it in GitHub Desktop.
Save wido/ac53ae01d661dd57f4a8 to your computer and use it in GitHub Desktop.
Ceph Health in Python in a loop
#!/usr/bin/env python
import time
import rados
import json
def get_cluster_health(r):
cmd = {"prefix":"status", "format":"json"}
ret, buf, errs = r.mon_command(json.dumps(cmd), b'', timeout=5)
result = json.loads(buf)
return result['health']['overall_status']
try:
r = rados.Rados(conffile="/etc/ceph/ceph.conf")
r.connect()
for i in range(1000):
print("{0}: {1}".format(time.time(), get_cluster_health(r)))
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
if r is not None:
r.shutdown()
@hikycool
Copy link

This way may be very slow when one or two monitor down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment