Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DataDog/dd-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed Sep 16, 2016
2 parents 4fedc57 + c9a01de commit c71e878
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 56 deletions.
99 changes: 52 additions & 47 deletions checks.d/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,64 +83,69 @@ def _extract_metrics(self, raw, tags):
self.log.debug('Error retrieving osdperf metrics')

try:
health = {'num_near_full_osds': 0, 'num_full_osds': 0}
# Health summary will be empty if no bad news
if raw['health_detail']['summary'] == []:
health = {'num_near_full_osds' : 0, 'num_full_osds' : 0}
self._publish(health, self.count, ['num_near_full_osds'], tags)
self._publish(health, self.count, ['num_full_osds'], tags)
else:
if raw['health_detail']['summary'] != []:
for osdhealth in raw['health_detail']['detail']:
osd, pct = self._osd_pct_used(osdhealth)
if osd:
local_tags = tags + ['ceph_osd:%s' % osd.replace('.','')]

if 'near' in osdhealth:
health = {'num_near_full_osds' : pct}
self._publish(health, self.count, ['num_near_full_osds'], local_tags)
health['num_near_full_osds'] += 1
local_health = {'osd.pct_used': pct}
self._publish(local_health, self.gauge, ['osd.pct_used'], local_tags)
else:
health = {'num_full_osds' : pct}
self._publish(health, self.count, ['num_full_osds'], local_tags)
health['num_full_osds'] += 1
local_health = {'osd.pct_used': pct}
self._publish(local_health, self.gauge, ['osd.pct_used'], local_tags)

self._publish(health, self.gauge, ['num_full_osds'], tags)
self._publish(health, self.gauge, ['num_near_full_osds'], tags)
except KeyError:
self.log.debug('Error retrieving health metrics')

for osdinfo in raw['osd_pool_stats']:
name = osdinfo.get('pool_name')
local_tags = tags + ['ceph_pool:%s' % name]
ops = 0
try:
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_op_per_sec'], local_tags)
ops += osdinfo['client_io_rate']['read_op_per_sec']
except KeyError:
osdinfo['client_io_rate'].update({'read_op_per_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_op_per_sec'], local_tags)

try:
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_op_per_sec'], local_tags)
ops += osdinfo['client_io_rate']['write_op_per_sec']
except KeyError:
osdinfo['client_io_rate'].update({'write_op_per_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_op_per_sec'], local_tags)

try:
osdinfo['client_io_rate']['op_per_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'op_per_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'op_per_sec' : ops})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'op_per_sec'], local_tags)

try:
osdinfo['client_io_rate']['read_bytes_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_bytes_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'read_bytes_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_bytes_sec'], local_tags)

try:
osdinfo['client_io_rate']['write_bytes_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_bytes_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'write_bytes_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_bytes_sec'], local_tags)
try:
for osdinfo in raw['osd_pool_stats']:
name = osdinfo.get('pool_name')
local_tags = tags + ['ceph_pool:%s' % name]
ops = 0
try:
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_op_per_sec'], local_tags)
ops += osdinfo['client_io_rate']['read_op_per_sec']
except KeyError:
osdinfo['client_io_rate'].update({'read_op_per_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_op_per_sec'], local_tags)

try:
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_op_per_sec'], local_tags)
ops += osdinfo['client_io_rate']['write_op_per_sec']
except KeyError:
osdinfo['client_io_rate'].update({'write_op_per_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_op_per_sec'], local_tags)

try:
osdinfo['client_io_rate']['op_per_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'op_per_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'op_per_sec' : ops})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'op_per_sec'], local_tags)

try:
osdinfo['client_io_rate']['read_bytes_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_bytes_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'read_bytes_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'read_bytes_sec'], local_tags)

try:
osdinfo['client_io_rate']['write_bytes_sec']
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_bytes_sec'], local_tags)
except KeyError:
osdinfo['client_io_rate'].update({'write_bytes_sec' : 0})
self._publish(osdinfo, self.gauge, ['client_io_rate', 'write_bytes_sec'], local_tags)
except KeyError:
self.log.debug('Error retrieving osd_pool_stats metrics')

try:
osdstatus = raw['status']['osdmap']['osdmap']
Expand Down
22 changes: 13 additions & 9 deletions tests/checks/mock/test_ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@ def test_osd_status_metrics(self):
}

self.run_check_twice(config, mocks=mocks, force_reload=True)
for osd in ['osd2']:
expected_tags = ['ceph_fsid:e0efcf84-e8ed-4916-8ce1-9c70242d390a','ceph_mon_state:leader',
'ceph_osd:%s' % osd]

for metric in ['ceph.num_full_osds']:
self.assertMetric(metric, count=1, tags=expected_tags)

for osd in ['osd1']:
for osd, pct_used in [('osd1', 94), ('osd2', 95)]:
expected_tags = ['ceph_fsid:e0efcf84-e8ed-4916-8ce1-9c70242d390a','ceph_mon_state:leader',
'ceph_osd:%s' % osd]

for metric in ['ceph.num_near_full_osds']:
self.assertMetric(metric, count=1, tags=expected_tags)
for metric in ['ceph.osd.pct_used']:
self.assertMetric(metric, value=pct_used, count=1, tags=expected_tags)

self.assertMetric('ceph.num_full_osds', value=1, count=1,
tags=['ceph_fsid:e0efcf84-e8ed-4916-8ce1-9c70242d390a', 'ceph_mon_state:leader'])
self.assertMetric('ceph.num_near_full_osds', value=1, count=1,
tags=['ceph_fsid:e0efcf84-e8ed-4916-8ce1-9c70242d390a', 'ceph_mon_state:leader'])

for pool in ['rbd', 'scbench']:
expected_tags = ['ceph_fsid:e0efcf84-e8ed-4916-8ce1-9c70242d390a','ceph_mon_state:leader',
Expand All @@ -93,3 +92,8 @@ def test_osd_status_metrics_non_osd_health(self):
}

self.run_check_twice(config, mocks=mocks, force_reload=True)

self.assertMetric('ceph.num_full_osds', value=0, count=1,
tags=['ceph_fsid:7d375c2a-902a-4990-93fd-ce21a296f444', 'ceph_mon_state:leader'])
self.assertMetric('ceph.num_near_full_osds', value=0, count=1,
tags=['ceph_fsid:7d375c2a-902a-4990-93fd-ce21a296f444', 'ceph_mon_state:leader'])

0 comments on commit c71e878

Please sign in to comment.