mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add prometheus datasource
This commit is contained in:
parent
866ea7f942
commit
6e66b8a0fa
@ -1,17 +1,18 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'kbn',
|
||||
'moment',
|
||||
'app/core/utils/datemath',
|
||||
'./directives',
|
||||
'./queryCtrl',
|
||||
],
|
||||
function (angular, _, kbn, dateMath) {
|
||||
function (angular, _, moment, dateMath) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
|
||||
var durationSplitRegexp = /(\d+)(ms|s|m|h|d|w|M|y)/;
|
||||
|
||||
module.factory('PrometheusDatasource', function($q, backendSrv, templateSrv) {
|
||||
|
||||
function PrometheusDatasource(datasource) {
|
||||
@ -183,13 +184,14 @@ function (angular, _, kbn, dateMath) {
|
||||
};
|
||||
|
||||
PrometheusDatasource.prototype.calculateInterval = function(interval, intervalFactor) {
|
||||
var sec = kbn.interval_to_seconds(interval);
|
||||
|
||||
var m = interval.match(durationSplitRegexp);
|
||||
var dur = moment.duration(parseInt(m[1]), m[2]);
|
||||
var sec = dur.asSeconds();
|
||||
if (sec < 1) {
|
||||
sec = 1;
|
||||
}
|
||||
|
||||
return sec * intervalFactor;
|
||||
return Math.floor(sec * intervalFactor) + 's';
|
||||
};
|
||||
|
||||
function transformMetricData(md, options) {
|
||||
|
@ -117,7 +117,7 @@ function (angular, _, kbn, dateMath) {
|
||||
$scope.calculateInterval = function() {
|
||||
var interval = $scope.target.interval || $scope.interval;
|
||||
var calculatedInterval = $scope.datasource.calculateInterval(interval, $scope.target.intervalFactor);
|
||||
$scope.target.calculatedInterval = kbn.secondsToHms(calculatedInterval);
|
||||
$scope.target.calculatedInterval = calculatedInterval;
|
||||
};
|
||||
|
||||
// TODO: validate target
|
||||
|
@ -21,7 +21,7 @@ define([
|
||||
var results;
|
||||
var urlExpected = '/api/v1/query_range?query=' +
|
||||
encodeURIComponent('test{job="testjob"}') +
|
||||
'&start=1443438675&end=1443460275&step=60';
|
||||
'&start=1443438675&end=1443460275&step=60s';
|
||||
var query = {
|
||||
range: { from: moment(1443438674760), to: moment(1443460274760) },
|
||||
targets: [{ expr: 'test{job="testjob"}' }],
|
||||
|
Loading…
Reference in New Issue
Block a user