mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added group by to Elasticsearch data source.
This commit is contained in:
parent
56d1411253
commit
a3e4abfd5e
@ -313,16 +313,23 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
|
||||
};
|
||||
|
||||
ElasticDatasource.prototype._getTimeSeries = function(results) {
|
||||
var _aggregation2timeSeries = function(aggregation) {
|
||||
var datapoints = aggregation.date_histogram.buckets.map(function(entry) {
|
||||
return [entry.stats.avg, entry.key];
|
||||
});
|
||||
return { target: aggregation.key, datapoints: datapoints };
|
||||
};
|
||||
var data = [];
|
||||
|
||||
if (results && results.aggregations) {
|
||||
for (var target in results.aggregations) {
|
||||
if (results.aggregations.hasOwnProperty(target) &&
|
||||
results.aggregations[target].date_histogram &&
|
||||
results.aggregations[target].date_histogram.buckets) {
|
||||
var datapoints = results.aggregations[target].date_histogram.buckets.map(function(entry) {
|
||||
return [entry.metric.avg, entry.key];
|
||||
});
|
||||
data.push({ target: target, datapoints: datapoints });
|
||||
if (!results.aggregations.hasOwnProperty(target)) {
|
||||
continue;
|
||||
}
|
||||
if (results.aggregations[target].date_histogram && results.aggregations[target].date_histogram.buckets) {
|
||||
data.push(_aggregation2timeSeries(results.aggregations[target]));
|
||||
} else if (results.aggregations[target].terms && results.aggregations[target].terms.buckets) {
|
||||
[].push.apply(data, results.aggregations[target].terms.buckets.map(_aggregation2timeSeries));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,22 +75,6 @@
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="tight-form" ng-hide="target.rawQuery">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item">
|
||||
<i class="fa fa-eye invisible"></i>
|
||||
</li>
|
||||
<li class="tight-form-item query-keyword" style="width: 75px;">
|
||||
Measurement
|
||||
</li>
|
||||
<li>
|
||||
<metric-segment segment="measurementSegment" get-alt-segments="getMeasurements()" on-value-changed="measurementChanged()"></metric-segment>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div> -->
|
||||
|
||||
<div class="tight-form" ng-hide="target.rawQuery">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item">
|
||||
@ -148,67 +132,21 @@
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="tight-form" ng-hide="target.rawQuery">
|
||||
<div class="tight-form" ng-hide="target.rawQuery">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item">
|
||||
<i class="fa fa-eye invisible"></i>
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item query-keyword" style="width: 75px;">
|
||||
WHERE
|
||||
</li>
|
||||
|
||||
<li ng-repeat="segment in tagSegments">
|
||||
<metric-segment segment="segment" get-alt-segments="getTagsOrValues(segment, $index)" on-value-changed="tagSegmentUpdated(segment, $index)"></metric-segment>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div> -->
|
||||
|
||||
<!-- <div class="tight-form">
|
||||
<ul class="tight-form-list" ng-hide="target.rawQuery">
|
||||
<li class="tight-form-item">
|
||||
<i class="fa fa-eye invisible"></i>
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item" >
|
||||
<span class="query-keyword">GROUP BY</span>
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item">
|
||||
time($interval)
|
||||
</li>
|
||||
|
||||
<li ng-repeat="segment in groupBySegments">
|
||||
<metric-segment segment="segment" get-alt-segments="getGroupByTagSegments(segment, 0)" on-value-changed="groupByTagUpdated(segment, $index)"></metric-segment>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
<a class="tight-form-item pointer" data-toggle="dropdown" bs-tooltip="'Insert missing values, important when stacking'" data-placement="right">
|
||||
<span ng-show="target.fill">
|
||||
fill ({{target.fill}})
|
||||
</span>
|
||||
<span ng-show="!target.fill">
|
||||
no fill
|
||||
</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a ng-click="target.fill = ''">no fill</a></li>
|
||||
<li><a ng-click="target.fill = 'null'">fill (null)</a></li>
|
||||
<li><a ng-click="target.fill = '0'">fill (0)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="tight-form-list pull-right">
|
||||
<li class="tight-form-item">
|
||||
Alias pattern
|
||||
Group By
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="input-medium tight-form-input" ng-model="target.alias" spellcheck='false' placeholder="alias" ng-blur="get_data()">
|
||||
<metric-segment segment="groupByFieldSegment" on-value-changed="groupByFieldChanged()"></metric-segment>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div> -->
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -29,7 +29,7 @@ function () {
|
||||
"min_doc_count": 0,
|
||||
},
|
||||
"aggs": {
|
||||
"metric": {
|
||||
"stats": {
|
||||
"stats": {
|
||||
"field": target.valueField
|
||||
}
|
||||
@ -38,6 +38,16 @@ function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (target.groupByField) {
|
||||
query["aggs"][target.termKey + "_" + target.termValue]["aggs"] = {
|
||||
"terms": {
|
||||
"terms": {
|
||||
"field": target.groupByField
|
||||
},
|
||||
"aggs": query["aggs"][target.termKey + "_" + target.termValue]["aggs"]
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
query = JSON.stringify(query);
|
||||
|
@ -44,6 +44,11 @@ function (angular, _, ElasticQueryBuilder) {
|
||||
}
|
||||
$scope.termValueSegment = new MetricSegment({value: target.termValue});
|
||||
|
||||
if (!target.groupByField) {
|
||||
target.groupByField = 'host.raw';
|
||||
}
|
||||
$scope.groupByFieldSegment = new MetricSegment({value: target.groupByField});
|
||||
|
||||
if (!target.measurement) {
|
||||
$scope.measurementSegment = MetricSegment.newSelectMeasurement();
|
||||
} else {
|
||||
@ -93,6 +98,11 @@ function (angular, _, ElasticQueryBuilder) {
|
||||
$scope.$parent.get_data();
|
||||
};
|
||||
|
||||
$scope.groupByFieldChanged = function() {
|
||||
$scope.target.groupBy = $scope.groupByFieldSegment.value;
|
||||
$scope.$parent.get_data();
|
||||
};
|
||||
|
||||
$scope.fixTagSegments = function() {
|
||||
var count = $scope.tagSegments.length;
|
||||
var lastSegment = $scope.tagSegments[Math.max(count-1, 0)];
|
||||
|
Loading…
Reference in New Issue
Block a user