Last active
June 16, 2020 07:42
-
-
Save wido/ac53ae01d661dd57f4a8 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']['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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This way may be very slow when one or two monitor down.