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

statsd: option to namespace all metrics #1210

Merged
merged 1 commit into from
Dec 31, 2014
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
5 changes: 5 additions & 0 deletions datadog.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ use_mount: no
# statsd_forward_host: address_of_own_statsd_server
# statsd_forward_port: 8125

# you may want all statsd metrics coming from this host to be namespaced
# in some way; if so, configure your namespace here. a metric that looks
# like `metric.name` will instead become `namespace.metric.name`
# statsd_metric_namespace:

# ========================================================================== #
# Service-specific configuration #
# ========================================================================== #
Expand Down
24 changes: 22 additions & 2 deletions dogstatsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from urllib import urlencode

# project
from aggregator import MetricsBucketAggregator
from aggregator import MetricsBucketAggregator, api_formatter
from checks.check_status import DogstatsdStatus
from config import get_config
from daemon import Daemon, AgentSupervisor
Expand Down Expand Up @@ -389,7 +389,27 @@ def init(config_path=None, use_watchdog=False, use_forwarder=False, args=None):
# server and reporting threads.
assert 0 < interval

aggregator = MetricsBucketAggregator(hostname, aggregator_interval, recent_point_threshold=recent_point_threshold)
formatter = api_formatter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
Could you put that in a new function something like:

def get_formatter(c):
  formatter = api_formatter

  if c['statsd_metric_namespace']:
    def metric_namespace_formatter_wrapper(*args, **kwargs):
      metric_prefix = c['statsd_metric_namespace']
      if metric_prefix[-1] != '.':
        metric_prefix += '.'

      metric = args[0]
      new_metric = metric_prefix + metric
      new_args = [new_metric] + args[1:]
      return api_formatter(*new_args, **kwargs)

    formatter = metric_namespace_formatter_wrapper
  return formatter

and then call that function in the init() function ?

if c['statsd_metric_namespace']:
def metric_namespace_formatter_wrapper(*args, **kwargs):
metric_prefix = c['statsd_metric_namespace']
if metric_prefix[-1] != '.':
metric_prefix += '.'

metric = args[0]
new_metric = metric_prefix + metric
new_args = [new_metric] + args[1:]
return api_formatter(*new_args, **kwargs)

formatter = metric_namespace_formatter_wrapper


aggregator = MetricsBucketAggregator(
hostname,
aggregator_interval,
recent_point_threshold=recent_point_threshold,
formatter = formatter
)

# Start the reporting thread.
reporter = Reporter(interval, aggregator, target, api_key, use_watchdog, event_chunk_size)
Expand Down