diff --git a/README.md b/README.md index 18779e2..6cccabf 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,14 @@ A plugin to connect etsy's statsD to Datadog datadogApiKey: "your_api_key" // You can get it from this page: https://app.datadoghq.com/account/settings#api datadogPrefix: "your_prefix" // Your metrics will be prefixed by this prefix datadogTags: ["your:tag", "another:tag"] // Your metrics will include these tags +datadogRemovePrefix: 2 // Number of period delimited prefixes to remove. If you use this option with *datadogPrefix* remove will happen prior to addition. +``` +### Example: + +If the metric name is called **"hosts.foo.bar.count"**, it will be rewritten to **"application.bar.count"**: +``` +datadogRemovePrefix: 2 +datadogPrefix: "application" ``` ## How to enable diff --git a/lib/datadog.js b/lib/datadog.js index 65f8a25..61788f4 100644 --- a/lib/datadog.js +++ b/lib/datadog.js @@ -27,6 +27,7 @@ var datadogApiHost; var datadogApiKey; var datadogStats = {}; var datadogPrefix; +var datadogRemovePrefix; var datadogTags; var Datadog = function(api_key, options) { @@ -192,11 +193,14 @@ var flush_stats = function datadog_post_stats(ts, metrics) { }; var get_prefix = function datadog_get_prefix(key) { + var new_key = key; + if (datadogRemovePrefix !== undefined) { + new_key = key.split(".").slice(datadogRemovePrefix).join('.'); + } if (datadogPrefix !== undefined) { - return [datadogPrefix, key].join('.'); - } else { - return key; + new_key = [datadogPrefix, new_key].join('.'); } + return new_key; } var backend_status = function datadog_status(writeCb) { @@ -215,6 +219,7 @@ exports.init = function datadog_init(startup_time, config, events, log) { datadogApiKey = config.datadogApiKey; datadogApiHost = config.datadogApiHost; datadogPrefix = config.datadogPrefix; + datadogRemovePrefix = config.datadogRemovePrefix; datadogTags = config.datadogTags; if (datadogTags === undefined || datadogTags.constructor !== Array || datadogTags.length < 1) {