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

support histograms, fix count submission #1616

Merged
merged 7 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions envoy/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ instances:
# supply a list of tags. The admin endpoint must be accessible.
# https://www.envoyproxy.io/docs/envoy/latest/operations/admin

# Add a `?usedonly` on the end if you wish to ignore
# unused metrics instead of reporting them as `0`.
- stats_url: http://localhost:80/stats

# tags:
Expand Down
29 changes: 14 additions & 15 deletions envoy/datadog_checks/envoy/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datadog_checks.checks import AgentCheck

from .errors import UnknownMetric, UnknownTags
from .parser import parse_metric
from .parser import parse_histogram, parse_metric


class Envoy(AgentCheck):
Expand Down Expand Up @@ -38,7 +38,7 @@ def check(self, instance):
timeout = int(instance.get('timeout', 20))

try:
request = requests.get(
response = requests.get(
stats_url, auth=auth, verify=verify_ssl, proxies=proxies, timeout=timeout
)
except requests.exceptions.Timeout:
Expand All @@ -52,29 +52,21 @@ def check(self, instance):
self.log.exception(msg)
return

if request.status_code != 200:
msg = 'Envoy endpoint `{}` responded with HTTP status code {}'.format(stats_url, request.status_code)
if response.status_code != 200:
msg = 'Envoy endpoint `{}` responded with HTTP status code {}'.format(stats_url, response.status_code)
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.CRITICAL, message=msg, tags=custom_tags)
self.log.warning(msg)
return

# Avoid repeated global lookups.
get_method = getattr

for line in request.content.decode().splitlines():
for line in response.content.decode().splitlines():
try:
envoy_metric, value = line.split(': ')
except ValueError:
continue

try:
value = int(value)
except (ValueError, TypeError):
self.log.debug(
'Unable to parse value `{}` as an integer for metric `{}`'.format(value, envoy_metric)
)
continue

try:
metric, tags, method = parse_metric(envoy_metric)
except UnknownMetric:
Expand All @@ -90,7 +82,14 @@ def check(self, instance):
self.unknown_tags[tag] += 1
continue

tags.extend(custom_tags)
get_method(self, method)(metric, value, tags=tags)
try:
value = int(value)
tags.extend(custom_tags)
get_method(self, method)(metric, value, tags=tags)

# If the value isn't an integer assume it's pre-computed histogram data.
except (ValueError, TypeError):
for metric, value in parse_histogram(metric, value):
self.gauge(metric, value, tags=tags)

self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=custom_tags)
Loading