Skip to content

Instantly share code, notes, and snippets.

@wido
Last active June 16, 2020 07:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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()
@hansbogert
Copy link

hansbogert commented Oct 2, 2017

The script no longer works since Luminous. The overall_status key is deprecated. Since this gist ranks pretty high on Google, can you update this to simply use the status key?

@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