Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic cleanups #3706

Merged
merged 1 commit into from
May 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions iis/datadog_checks/iis/iis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
["Web Service", None, "ISAPI Extension Requests/sec", "iis.requests.isapi", "gauge"],
]

TOTAL_SITE = "_Total"


class IIS(PDHBaseCheck):
SERVICE_CHECK = "iis.site_up"
Expand All @@ -60,10 +62,9 @@ def check(self, instance):
expected_sites = set(sites)
# _Total should always be in the list of expected sites; we always
# report _Total
if "_Total" not in expected_sites:
expected_sites.add("_Total")
expected_sites.add(TOTAL_SITE)

self.log.debug("expected sites is {}".format(str(expected_sites)))
self.log.debug("Expected sites is {}".format(expected_sites))
key = hash_mutable(instance)
for inst_name, dd_name, metric_func, counter in self._metrics[key]:
try:
Expand All @@ -81,39 +82,30 @@ def check(self, instance):

try:
if not counter.is_single_instance():
# Skip any sites we don't specifically want.
if not sites:
tags.append("site:{0}".format(self.normalize(sitename)))
# always report total
elif sitename == "_Total":
tags.append("site:{0}".format(self.normalize(sitename)))
elif sitename not in sites:
if sites and sitename != TOTAL_SITE and sitename not in sites:
continue
else:
tags.append("site:{0}".format(self.normalize(sitename)))
tags.append("site:{}".format(self.normalize(sitename)))
except Exception as e:
self.log.error("Caught exception {} setting tags".format(str(e)))
self.log.error("Caught exception {} setting tags".format(e))

try:
metric_func(dd_name, val, tags)
except Exception as e:
self.log.error("metric_func: {} {} {}".format(dd_name, str(val), str(e)))
pass
self.log.error("Error in metric_func: {} {} {}".format(dd_name, val, e))

if dd_name == "iis.uptime":
uptime = int(val)
status = AgentCheck.CRITICAL if uptime == 0 else AgentCheck.OK
self.service_check(self.SERVICE_CHECK, status, tags)
if sitename in expected_sites:
self.log.debug("Removing {} from expected sites".format(sitename))
self.log.debug("Removing {!r} from expected sites".format(sitename))
expected_sites.remove(sitename)
else:
self.log.warning("site not in expected_sites {}".format(sitename))
self.log.warning("Site {!r} not in expected_sites".format(sitename))

except Exception as e:
# don't give up on all of the metrics because one failed
self.log.error("IIS Failed to get metric data for {} {}: {}".format(inst_name, dd_name, str(e)))
pass
self.log.error("IIS Failed to get metric data for {} {}: {}".format(inst_name, dd_name, e))

for site in expected_sites:
tags = []
Expand Down