From: Kefu Chai Date: Wed, 27 Jun 2018 04:24:07 +0000 (+0800) Subject: Merge pull request #22418 from wido/mgr-telegraf-generator X-Git-Tag: v14.0.1~1004 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cc758a7eca4d054499423c95e4394ecb46c0bf96;p=ceph.git Merge pull request #22418 from wido/mgr-telegraf-generator mgr/telegraf: Use Python generator and catch OSError Reviewed-by: John Spray Reviewed-by: Kefu Chai --- cc758a7eca4d054499423c95e4394ecb46c0bf96 diff --cc src/pybind/mgr/telegraf/module.py index ec05de71c215,e33d1ebf0116..8bda403e98d5 --- a/src/pybind/mgr/telegraf/module.py +++ b/src/pybind/mgr/telegraf/module.py @@@ -123,36 -119,8 +119,34 @@@ class Module(MgrModule) 'fsid': self.get_fsid() }, 'value': counter_info['value'] - }) - - return data + } + def get_pg_stats(self): + stats = dict() + + pg_status = self.get('pg_status') + for key in ['bytes_total', 'data_bytes', 'bytes_used', 'bytes_avail', + 'num_pgs', 'num_objects', 'num_pools']: + stats[key] = pg_status[key] + + pg_states = ['active', 'peering', 'clean', 'scrubbing', 'undersized', + 'backfilling', 'recovering', 'degraded', 'inconsistent', + 'remapped', 'backfill_toofull', 'wait_backfill', + 'recovery_wait'] + + for state in pg_states: + stats['num_pgs_{0}'.format(state)] = 0 + + stats['num_pgs'] = pg_status['num_pgs'] + for state in pg_status['pgs_by_state']: + states = state['state_name'].split('+') + for s in pg_states: + key = 'num_pgs_{0}'.format(s) + if s in states: + stats[key] += state['count'] + + return stats + def get_cluster_stats(self): stats = dict() @@@ -200,11 -168,32 +194,10 @@@ stats['num_mds_up'] = num_mds_up stats['num_mds'] = num_mds_up + stats['num_mds_standby'] - pg_status = self.get('pg_status') - for key in ['bytes_total', 'data_bytes', 'bytes_used', 'bytes_avail', - 'num_pgs', 'num_objects', 'num_pools']: - stats[key] = pg_status[key] - - stats['num_pgs_active'] = 0 - stats['num_pgs_clean'] = 0 - stats['num_pgs_scrubbing'] = 0 - stats['num_pgs_peering'] = 0 - for state in pg_status['pgs_by_state']: - states = state['state_name'].split('+') - - if 'active' in states: - stats['num_pgs_active'] += state['count'] - - if 'clean' in states: - stats['num_pgs_clean'] += state['count'] - - if 'peering' in states: - stats['num_pgs_peering'] += state['count'] - - if 'scrubbing' in states: - stats['num_pgs_scrubbing'] += state['count'] + stats.update(self.get_pg_stats()) - data = list() for key, value in stats.items(): - data.append({ + yield { 'measurement': 'ceph_cluster_stats', 'tags': { 'type_instance': key,