Remove OSD stat collection if count is zero

Otherwise, ceph osd df will hang indefinitely trying to get data
for the zero OSDs.
This commit is contained in:
Joshua Boniface 2019-06-18 12:36:53 -04:00
parent 5a327dc41a
commit 8d9007f697
1 changed files with 108 additions and 101 deletions

View File

@ -912,12 +912,15 @@ def update_zookeeper():
} }
}) })
# Trigger updates for each OSD on this node # Trigger updates for each pool on this node
for pool in pool_list: for pool in pool_list:
zkhandler.writedata(zk_conn, { zkhandler.writedata(zk_conn, {
'/ceph/pools/{}/stats'.format(pool): str(json.dumps(pool_df[pool])) '/ceph/pools/{}/stats'.format(pool): str(json.dumps(pool_df[pool]))
}) })
# Only grab OSD stats if there are OSDs to grab (otherwise `ceph osd df` hangs)
osds_this_node = 0
if len(osd_list) > 0:
# Get data from Ceph OSDs # Get data from Ceph OSDs
if debug: if debug:
print("Get data from Ceph OSDs") print("Get data from Ceph OSDs")
@ -936,12 +939,17 @@ def update_zookeeper():
'primary_affinity': osd['primary_affinity'] 'primary_affinity': osd['primary_affinity']
} }
}) })
# Parse the df data # Parse the df data
if debug: if debug:
print("Parse the OSD df data") print("Parse the OSD df data")
osd_df = dict() osd_df = dict()
retcode, stdout, stderr = common.run_os_command('ceph osd df --format json') retcode, stdout, stderr = common.run_os_command('ceph osd df --format json')
try:
osd_df_raw = json.loads(stdout)['nodes'] osd_df_raw = json.loads(stdout)['nodes']
except:
logger.out('Failed to parse OSD list', state='w')
if debug: if debug:
print("Loop through OSD df") print("Loop through OSD df")
for osd in osd_df_raw: for osd in osd_df_raw:
@ -1003,7 +1011,6 @@ def update_zookeeper():
# Trigger updates for each OSD on this node # Trigger updates for each OSD on this node
if debug: if debug:
print("Trigger updates for each OSD on this node") print("Trigger updates for each OSD on this node")
osds_this_node = 0
for osd in osd_list: for osd in osd_list:
if d_osd[osd].node == myhostname: if d_osd[osd].node == myhostname:
zkhandler.writedata(zk_conn, { zkhandler.writedata(zk_conn, {