Commit a6d25908 by Torkel Ödegaard

Merge PR #618

parents c48b6e23 923cd045
......@@ -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
......
......@@ -43,7 +43,7 @@
<ul class="grafana-segment-list" role="menu">
<li>
<input type="text"
class="input-xxlarge grafana-target-segment-input"
class="grafana-target-segment-input"
ng-model="target.metric"
spellcheck='false'
bs-typeahead="suggestMetrics"
......@@ -59,6 +59,7 @@
</li>
<li class="grafana-target-segment">
Aggregator
</li>
<li>
<select ng-model="target.aggregator"
class="grafana-target-segment-input input-small"
......@@ -88,6 +89,20 @@
ng-model="target.isCounter"
ng-change="targetBlur()">
</li>
<li class="grafana-target-segment">
Alias:
</li>
<li>
<input type="text"
class="grafana-target-segment-input input-medium"
ng-model="target.alias"
spellcheck='false'
placeholder="series alias"
data-min-length=0 data-items=100
ng-blur="targetBlur()"
/>
</li>
</ul>
<div class="clearfix"></div>
......
......@@ -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]);
function createMetricLabel(metric, tagData, options) {
if (options.alias) {
return options.alias;
}
});
if (!_.isEmpty(tagData)) {
target = target + "{" + tagData.join(", ") + "}";
}
metric += "{" + tagData.join(", ") + "}";
}
return { target: target, datapoints: dps };
return metric;
}
function convertTargetToQuery(target) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment