Skip to content

Instantly share code, notes, and snippets.

@hansbogert
Forked from wido/ceph-health.py
Last active October 2, 2017 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hansbogert/5bcc36d1b4e5e90244555122ea5bd860 to your computer and use it in GitHub Desktop.
Save hansbogert/5bcc36d1b4e5e90244555122ea5bd860 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']['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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment