mirror of
https://github.com/grafana/grafana.git
synced 2025-01-24 23:37:01 -06:00
moved annotations graphite query to graphite datasource
This commit is contained in:
parent
7d6eafb2f2
commit
9eb9bd8488
@ -31,10 +31,16 @@ define([
|
|||||||
return promiseCached;
|
return promiseCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
var graphiteMetrics = this.getGraphiteMetrics(filterSrv, rangeUnparsed);
|
var annotations = _.where(annotationPanel.annotations, { enable: true });
|
||||||
var graphiteEvents = this.getGraphiteEvents(rangeUnparsed);
|
|
||||||
|
|
||||||
promiseCached = $q.all(graphiteMetrics.concat(graphiteEvents))
|
var promises = _.map(annotations, function(annotation) {
|
||||||
|
var datasource = datasourceSrv.get(annotation.datasource);
|
||||||
|
return datasource.annotationQuery(annotation, filterSrv, rangeUnparsed)
|
||||||
|
.then(this.receiveAnnotationResults)
|
||||||
|
.then(null, errorHandler);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
promiseCached = $q.all(promises)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
@ -42,6 +48,20 @@ define([
|
|||||||
return promiseCached;
|
return promiseCached;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.receiveAnnotationResults = function(results) {
|
||||||
|
console.log('Annotation result!', results);
|
||||||
|
for (var i = 0; i < results.length; i++) {
|
||||||
|
var data = results[i];
|
||||||
|
addAnnotation({
|
||||||
|
annotation: data.annotation,
|
||||||
|
time: data.time,
|
||||||
|
description: data.description,
|
||||||
|
tags: data.tags,
|
||||||
|
data: data.text
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.getGraphiteEvents = function(rangeUnparsed) {
|
this.getGraphiteEvents = function(rangeUnparsed) {
|
||||||
var annotations = this.getAnnotationsByType('graphite events');
|
var annotations = this.getAnnotationsByType('graphite events');
|
||||||
if (annotations.length === 0) {
|
if (annotations.length === 0) {
|
||||||
|
@ -57,6 +57,37 @@ function (angular, _, $, config, kbn, moment) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GraphiteDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) {
|
||||||
|
var graphiteQuery = {
|
||||||
|
range: rangeUnparsed,
|
||||||
|
targets: [{ target: annotation.target }],
|
||||||
|
format: 'json',
|
||||||
|
maxDataPoints: 100
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.query(filterSrv, graphiteQuery)
|
||||||
|
.then(function(result) {
|
||||||
|
var list = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < result.data.length; i++) {
|
||||||
|
var target = result.data[i];
|
||||||
|
|
||||||
|
for (var y = 0; y < target.datapoints.length; y++) {
|
||||||
|
var datapoint = target.datapoints[y];
|
||||||
|
if (!datapoint[0]) { continue; }
|
||||||
|
|
||||||
|
list.push({
|
||||||
|
annotation: annotation,
|
||||||
|
time: datapoint[1] * 1000,
|
||||||
|
description: target.target
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
GraphiteDatasource.prototype.events = function(options) {
|
GraphiteDatasource.prototype.events = function(options) {
|
||||||
try {
|
try {
|
||||||
var tags = '';
|
var tags = '';
|
||||||
|
Loading…
Reference in New Issue
Block a user