diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae62ae6e98d..55195b3d9ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
- [Issue #556](https://github.com/grafana/grafana/issues/556). Chart: New legend display option "Right side", will show legend to the right of the graph
- [Issue #604](https://github.com/grafana/grafana/issues/604). Chart: New axis format, 'bps' (SI unit in steps of 1000) useful for network gear metics
- [Issue #626](https://github.com/grafana/grafana/issues/626). Chart: Downscale y axis to more precise unit, value of 0.1 for seconds format will be formated as 100 ms. Thanks @kamaradclimber
+- [Issue #618](https://github.com/grafana/grafana/issues/618). OpenTSDB: Series alias option to override metric name returned from opentsdb. Thanks @heldr
**Changes**
- [Issue #536](https://github.com/grafana/grafana/issues/536). Graphite: Use unix epoch for Graphite from/to for absolute time ranges
diff --git a/src/app/partials/opentsdb/editor.html b/src/app/partials/opentsdb/editor.html
index 673c5a68cc4..797e7c0fa72 100644
--- a/src/app/partials/opentsdb/editor.html
+++ b/src/app/partials/opentsdb/editor.html
@@ -43,7 +43,7 @@
diff --git a/src/app/services/opentsdb/opentsdbDatasource.js b/src/app/services/opentsdb/opentsdbDatasource.js
index d29e754ce42..c46c3084678 100644
--- a/src/app/services/opentsdb/opentsdbDatasource.js
+++ b/src/app/services/opentsdb/opentsdbDatasource.js
@@ -15,6 +15,7 @@ function (angular, _, kbn) {
this.editorSrc = 'app/partials/opentsdb/editor.html';
this.url = datasource.url;
this.name = datasource.name;
+ this.supportMetrics = true;
}
// Called once per panel (graph)
@@ -38,12 +39,12 @@ function (angular, _, kbn) {
});
return this.performTimeSeriesQuery(queries, start, end)
- .then(function(response) {
- var result = _.map(response.data, function(metricData) {
- return transformMetricData(metricData, groupByTags);
- });
+ .then(_.bind(function(response) {
+ var result = _.map(response.data, _.bind(function(metricData, index) {
+ return transformMetricData(metricData, groupByTags, this.targets[index]);
+ }, this));
return { data: result };
- });
+ }, options));
};
OpenTSDBDatasource.prototype.performTimeSeriesQuery = function(queries, start, end) {
@@ -80,8 +81,20 @@ function (angular, _, kbn) {
});
};
- function transformMetricData(md, groupByTags) {
- var dps = [];
+ function transformMetricData(md, groupByTags, options) {
+ var dps = [],
+ tagData = [],
+ metricLabel = null;
+
+ if (!_.isEmpty(md.tags)) {
+ _.each(_.pairs(md.tags), function(tag) {
+ if (_.has(groupByTags, tag[0])) {
+ tagData.push(tag[0] + "=" + tag[1]);
+ }
+ });
+ }
+
+ metricLabel = createMetricLabel(md.metric, tagData, options);
// TSDB returns datapoints has a hash of ts => value.
// Can't use _.pairs(invert()) because it stringifies keys/values
@@ -89,22 +102,19 @@ function (angular, _, kbn) {
dps.push([v, k]);
});
- var target = md.metric;
- if (!_.isEmpty(md.tags)) {
- var tagData = [];
+ return { target: metricLabel, datapoints: dps };
+ }
- _.each(_.pairs(md.tags), function(tag) {
- if (_.has(groupByTags, tag[0])) {
- tagData.push(tag[0] + "=" + tag[1]);
- }
- });
-
- if (!_.isEmpty(tagData)) {
- target = target + "{" + tagData.join(", ") + "}";
- }
+ function createMetricLabel(metric, tagData, options) {
+ if (options.alias) {
+ return options.alias;
}
- return { target: target, datapoints: dps };
+ if (!_.isEmpty(tagData)) {
+ metric += "{" + tagData.join(", ") + "}";
+ }
+
+ return metric;
}
function convertTargetToQuery(target) {