-
-
Save hansbogert/5bcc36d1b4e5e90244555122ea5bd860 to your computer and use it in GitHub Desktop.
Ceph Health in Python in a loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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