Skip to content

Commit

Permalink
Merge pull request #1210 from igor47/statsd_metric_namespace
Browse files Browse the repository at this point in the history
statsd: option to namespace all metrics
  • Loading branch information
Remi Hakim committed Dec 31, 2014
2 parents 43df4fc + 2eb4ba3 commit bdc1354
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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
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

0 comments on commit bdc1354

Please sign in to comment.