Skip to content

Commit

Permalink
Clean up ceph osd tags
Browse files Browse the repository at this point in the history
We only need to iterate through the metadata once
  • Loading branch information
mxmeinhold committed Jun 7, 2023
1 parent e671a96 commit 0a1540d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ceph/datadog_checks/ceph/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ def _publish(self, raw, func, keyspec, tags):
def _extract_metrics(self, raw, tags):
try:
raw_osd_perf = raw.get('osd_perf', {}).get('osdstats', raw.get('osd_perf'))
store_type = { metadata['id']: metadata['osd_objectstore'] for metadata in raw.get('osd_metadata', []) }
devices = { metadata['id']: metadata['devices'] for metadata in raw.get('osd_metadata', []) }
device_ids = { metadata['id']: metadata['device_ids'] for metadata in raw.get('osd_metadata', []) }
device_class = { metadata['id']: metadata['default_device_class'] for metadata in raw.get('osd_metadata', []) }
version = { metadata['id']: metadata['ceph_version_short'] for metadata in raw.get('osd_metadata', []) }
release = { metadata['id']: metadata['ceph_release'] for metadata in raw.get('osd_metadata', []) }
osd_tags = { metadata['id']: [
f'ceph_osd_objectstore:{metadata["osd_objectstore"]}',
f'ceph_osd_device:{metadata["devices"]}',
f'ceph_osd_device_id:{metadata["device_ids"]}',
f'ceph_osd_device_class:{metadata["default_device_class"]}',
f'ceph_version:{metadata["ceph_version_short"]}',
f'ceph_release:{metadata["ceph_release"]}',
] for metadata in raw.get('osd_metadata', []) }

for osdperf in raw_osd_perf['osd_perf_infos']:
local_tags = tags + ['ceph_osd:osd%s' % osdperf['id'], f'ceph_osd_objectstore:{store_type[osdperf["id"]]}', f'ceph_osd_device:{devices[osdperf["id"]]}', f'ceph_osd_device_id:{device_ids[osdperf["id"]]}', f'ceph_osd_device_class:{device_class[osdperf["id"]]}', f'ceph_version:{version[osdperf["id"]]}', f'ceph_release:{release[osdperf["id"]]}']
local_tags = tags + [f'ceph_osd:osd{osdperf["id"]}'] + osd_tags.get(osdperf['id'], [])
self._publish(osdperf, self.gauge, ['perf_stats', 'apply_latency_ms'], local_tags)
self._publish(osdperf, self.gauge, ['perf_stats', 'commit_latency_ms'], local_tags)
except (KeyError, TypeError):
Expand Down

0 comments on commit 0a1540d

Please sign in to comment.