Skip to content

Commit

Permalink
[etcd] send service check ok when all is fine
Browse files Browse the repository at this point in the history
And not only CRITICAL when unable to get metrics.
This is needed as the service check won't appear on the monitor screen
otherwise.
Fix python2.6 compatibility issue: "{}".format()
  • Loading branch information
degemer committed Feb 19, 2015
1 parent 10fed16 commit c3ae0e6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions checks.d/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check(self, instance):
instance_tags = instance.get('tags', [])
# Append the instance's URL in case there are more than one, that
# way they can tell the difference!
instance_tags.append("url:{}".format(url))
instance_tags.append("url:{0}".format(url))
timeout = float(instance.get('timeout', self.DEFAULT_TIMEOUT))

self_response = self.get_self_metrics(url, timeout)
Expand All @@ -68,27 +68,30 @@ def check(self, instance):
if key in self_response:
self.rate(self.SELF_RATES[key], self_response[key], tags=instance_tags)
else:
self.log.warn("Missing key {} in stats.".format(key))
self.log.warn("Missing key {0} in stats.".format(key))

for key in self.SELF_GAUGES:
if key in self_response:
self.gauge(self.SELF_GAUGES[key], self_response[key], tags=instance_tags)
else:
self.log.warn("Missing key {} in stats.".format(key))
self.log.warn("Missing key {0} in stats.".format(key))

store_response = self.get_store_metrics(url, timeout)
if store_response is not None:
for key in self.STORE_RATES:
if key in store_response:
self.rate(self.STORE_RATES[key], store_response[key], tags=instance_tags)
else:
self.log.warn("Missing key {} in stats.".format(key))
self.log.warn("Missing key {0} in stats.".format(key))

for key in self.STORE_GAUGES:
if key in store_response:
self.gauge(self.STORE_GAUGES[key], store_response[key], tags=instance_tags)
else:
self.log.warn("Missing key {} in stats.".format(key))
self.log.warn("Missing key {0} in stats.".format(key))

if self_response is not None and store_response is not None:
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=instance_tags)

def get_self_metrics(self, url, timeout):
return self.get_json(url + "/v2/stats/self", timeout)
Expand All @@ -103,13 +106,13 @@ def get_json(self, url, timeout):
# If there's a timeout
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL,
message="Timeout when hitting %s" % url,
tags = ["url:{}".format(url)])
return None
tags = ["url:{0}".format(url)])
raise

if r.status_code != 200:
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL,
message="Got %s when hitting %s" % (r.status_code, url),
tags = ["url:{}".format(url)])
return None
tags = ["url:{0}".format(url)])
raise Exception("Http status code {0} on url {1}".format(r.status_code, url))

return r.json()

0 comments on commit c3ae0e6

Please sign in to comment.