|
@@ -54,86 +54,11 @@ define([
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- this.getGraphiteEvents = function(rangeUnparsed) {
|
|
|
|
|
- var annotations = this.getAnnotationsByType('graphite events');
|
|
|
|
|
- if (annotations.length === 0) {
|
|
|
|
|
- return [];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var promises = _.map(annotations, function(annotation) {
|
|
|
|
|
-
|
|
|
|
|
- return datasourceSrv.default.events({ range: rangeUnparsed, tags: annotation.tags })
|
|
|
|
|
- .then(function(results) {
|
|
|
|
|
- _.each(results.data, function (event) {
|
|
|
|
|
- addAnnotation({
|
|
|
|
|
- annotation: annotation,
|
|
|
|
|
- time: event.when * 1000,
|
|
|
|
|
- description: event.what,
|
|
|
|
|
- tags: event.tags,
|
|
|
|
|
- data: event.data
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- })
|
|
|
|
|
- .then(null, errorHandler);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return promises;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- this.getAnnotationsByType = function(type) {
|
|
|
|
|
- return _.where(annotationPanel.annotations, {
|
|
|
|
|
- type: type,
|
|
|
|
|
- enable: true
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- this.getGraphiteMetrics = function(filterSrv, rangeUnparsed) {
|
|
|
|
|
- var annotations = this.getAnnotationsByType('graphite metric');
|
|
|
|
|
- if (annotations.length === 0) {
|
|
|
|
|
- return [];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var promises = _.map(annotations, function(annotation) {
|
|
|
|
|
- var graphiteQuery = {
|
|
|
|
|
- range: rangeUnparsed,
|
|
|
|
|
- targets: [{ target: annotation.target }],
|
|
|
|
|
- format: 'json',
|
|
|
|
|
- maxDataPoints: 100
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- var receiveFunc = _.partial(receiveGraphiteMetrics, annotation);
|
|
|
|
|
-
|
|
|
|
|
- return datasourceSrv.default.query(filterSrv, graphiteQuery)
|
|
|
|
|
- .then(receiveFunc)
|
|
|
|
|
- .then(null, errorHandler);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return promises;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
function errorHandler(err) {
|
|
function errorHandler(err) {
|
|
|
console.log('Annotation error: ', err);
|
|
console.log('Annotation error: ', err);
|
|
|
alertSrv.set('Annotations','Could not fetch annotations','error');
|
|
alertSrv.set('Annotations','Could not fetch annotations','error');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function receiveGraphiteMetrics(annotation, results) {
|
|
|
|
|
- for (var i = 0; i < results.data.length; i++) {
|
|
|
|
|
- var target = results.data[i];
|
|
|
|
|
-
|
|
|
|
|
- for (var y = 0; y < target.datapoints.length; y++) {
|
|
|
|
|
- var datapoint = target.datapoints[y];
|
|
|
|
|
-
|
|
|
|
|
- if (datapoint[0]) {
|
|
|
|
|
- addAnnotation({
|
|
|
|
|
- annotation: annotation,
|
|
|
|
|
- time: datapoint[1] * 1000,
|
|
|
|
|
- description: target.target
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function addAnnotation(options) {
|
|
function addAnnotation(options) {
|
|
|
var tooltip = "<small><b>" + options.title + "</b><br/>";
|
|
var tooltip = "<small><b>" + options.title + "</b><br/>";
|
|
|
if (options.tags) {
|
|
if (options.tags) {
|