Merge pull request #4296 from knowroozi/opentsdb_annotations

add annotations for opentsdb
This commit is contained in:
Carl Bergquist 2016-03-09 11:31:05 +01:00
commit ac439d83fe
4 changed files with 53 additions and 3 deletions

View File

@ -69,6 +69,40 @@ function (angular, _, dateMath) {
}.bind(this));
};
this.annotationQuery = function(options) {
var start = convertToTSDBTime(options.rangeRaw.from, false);
var end = convertToTSDBTime(options.rangeRaw.to, true);
var qs = [];
var eventList = [];
qs.push({ aggregator:"sum", metric:options.annotation.target });
var queries = _.compact(qs);
return this.performTimeSeriesQuery(queries, start, end).then(function(results) {
if(results.data[0]) {
var annotationObject = results.data[0].annotations;
if(options.annotation.isGlobal){
annotationObject = results.data[0].globalAnnotations;
}
if(annotationObject) {
_.each(annotationObject, function(annotation) {
var event = {
title: annotation.description,
time: Math.floor(annotation.startTime) * 1000,
text: annotation.notes,
annotation: options.annotation
};
eventList.push(event);
});
}
}
return eventList;
}.bind(this));
};
this.performTimeSeriesQuery = function(queries, start, end) {
var msResolution = false;
if (this.tsdbResolution === 2) {
@ -77,7 +111,8 @@ function (angular, _, dateMath) {
var reqBody = {
start: start,
queries: queries,
msResolution: msResolution
msResolution: msResolution,
globalAnnotations: true
};
// Relative queries (e.g. last hour) don't include an end time

View File

@ -2,9 +2,13 @@ import {OpenTsDatasource} from './datasource';
import {OpenTsQueryCtrl} from './query_ctrl';
import {OpenTsConfigCtrl} from './config_ctrl';
class AnnotationsQueryCtrl {
static templateUrl = 'partials/annotations.editor.html';
}
export {
OpenTsDatasource as Datasource,
OpenTsQueryCtrl as QueryCtrl,
OpenTsConfigCtrl as ConfigCtrl,
AnnotationsQueryCtrl as AnnotationsQueryCtrl
};

View File

@ -0,0 +1,10 @@
<div class="gf-form-group">
<div class="gf-form">
<span class="gf-form-label width-13">OpenTSDB metrics query</span>
<input type="text" class="gf-form-input" ng-model='ctrl.annotation.target' placeholder="events.eventname"></input>
</div>
<div class="gf-form">
<span class="gf-form-label width-13">Show Global Annotations?</span>
<editor-checkbox text="" model="ctrl.annotation.isGlobal"></editor-checkbox>
</div>
</div>

View File

@ -4,5 +4,6 @@
"id": "opentsdb",
"metrics": true,
"defaultMatchFormat": "pipe"
"defaultMatchFormat": "pipe",
"annotations": true
}