Skip to content

Commit

Permalink
Merge pull request #1173 from DataDog/tokumx_service_check
Browse files Browse the repository at this point in the history
Add tokumx service check
  • Loading branch information
LeoCavaille committed Dec 10, 2014
2 parents 6842ec4 + 8dc51ea commit 9bc9f1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
30 changes: 26 additions & 4 deletions checks.d/tokumx.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def submit(self, val):
self.submit_histogram()

class TokuMX(AgentCheck):
SERVICE_CHECK_NAME = 'tokumx.can_connect'

GAUGES = [
"indexCounters.btree.missRatio",
Expand Down Expand Up @@ -267,16 +268,37 @@ def _get_connection(self, instance):
self.log.info('No TokuMX database found in URI. Defaulting to admin.')
db_name = 'admin'

service_check_tags = [
"db:%s" % db_name
]

nodelist = parsed.get('nodelist')
if nodelist:
host = nodelist[0][0]
port = nodelist[0][1]
service_check_tags = service_check_tags + [
"host:%s" % host,
"port:%s" % port
]

do_auth = True
if username is None or password is None:
self.log.debug("TokuMX: cannot extract username and password from config %s" % server)
do_auth = False
try:
conn = MongoClient(server, socketTimeoutMS=DEFAULT_TIMEOUT*1000, **ssl_params)
db = conn[db_name]
except Exception:
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, tags=service_check_tags)
raise

conn = MongoClient(server, socketTimeoutMS=DEFAULT_TIMEOUT*1000, **ssl_params)
db = conn[db_name]
if do_auth:
if not db.authenticate(username, password):
raise Exception("TokuMX: cannot connect with config %s" % server)
message = "TokuMX: cannot connect with config %s" % server
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, tags=service_check_tags, message=message)
raise Exception(message)

self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=service_check_tags)

return server, conn, db, tags

Expand Down Expand Up @@ -426,6 +448,6 @@ def check(self, instance):

if conn.is_mongos:
self.collect_mongos(server, conn, db, tags)

else:
self.collect_metrics(server, conn, db, tags)
12 changes: 12 additions & 0 deletions tests/test_tokumx.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def testTokuMXCheck(self):
# Run the check again so we get the rates
self.check.check(self.config['instances'][1])

# Service checks
service_checks = self.check.get_service_checks()
print service_checks
service_checks_count = len(service_checks)
self.assertTrue(type(service_checks) == type([]))
self.assertTrue(service_checks_count > 0)
self.assertEquals(len([sc for sc in service_checks if sc['check'] == self.check.SERVICE_CHECK_NAME]), 4, service_checks)
# Assert that all service checks have the proper tags: host and port
self.assertEquals(len([sc for sc in service_checks if "host:localhost" in sc['tags']]), service_checks_count, service_checks)
self.assertEquals(len([sc for sc in service_checks if "port:%s" % PORT1 in sc['tags'] or "port:%s" % PORT2 in sc['tags']]), service_checks_count, service_checks)
self.assertEquals(len([sc for sc in service_checks if "db:test" in sc['tags']]), service_checks_count, service_checks)

# Metric assertions
metrics = self.check.get_metrics()
assert metrics
Expand Down

0 comments on commit 9bc9f1e

Please sign in to comment.