mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
ca940c2ae5
commit
27e486d678
@ -1,13 +1,9 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
],
|
||||
function (angular, _) {
|
||||
'use strict';
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
|
||||
var module = angular.module('grafana.controllers');
|
||||
export class CloudWatchQueryParameter {
|
||||
|
||||
module.directive('cloudwatchQueryParameter', function() {
|
||||
constructor() {
|
||||
return {
|
||||
templateUrl: 'public/app/plugins/datasource/cloudwatch/partials/query.parameter.html',
|
||||
controller: 'CloudWatchQueryParameterCtrl',
|
||||
@ -18,9 +14,12 @@ function (angular, _) {
|
||||
onChange: "&",
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.controller('CloudWatchQueryParameterCtrl', function($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) {
|
||||
export class CloudWatchQueryParameterCtrl {
|
||||
|
||||
constructor($scope, templateSrv, uiSegmentSrv, datasourceSrv, $q) {
|
||||
|
||||
$scope.init = function() {
|
||||
var target = $scope.target;
|
||||
@ -120,8 +119,7 @@ function (angular, _) {
|
||||
|
||||
if (segment.value === $scope.removeDimSegment.value) {
|
||||
$scope.dimSegments.splice(index, 3);
|
||||
}
|
||||
else if (segment.type === 'plus-button') {
|
||||
} else if (segment.type === 'plus-button') {
|
||||
$scope.dimSegments.push(uiSegmentSrv.newOperator('='));
|
||||
$scope.dimSegments.push(uiSegmentSrv.newFake('select dimension value', 'value', 'query-segment-value'));
|
||||
segment.type = 'key';
|
||||
@ -195,7 +193,8 @@ function (angular, _) {
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
angular.module('grafana.controllers').directive('cloudwatchQueryParameter', CloudWatchQueryParameter);
|
||||
angular.module('grafana.controllers').controller('CloudWatchQueryParameterCtrl', CloudWatchQueryParameterCtrl);
|
@ -1,136 +0,0 @@
|
||||
define([
|
||||
'lodash'
|
||||
],
|
||||
function (_) {
|
||||
'use strict';
|
||||
|
||||
function PrometheusMetricFindQuery(datasource, query, timeSrv) {
|
||||
this.datasource = datasource;
|
||||
this.query = query;
|
||||
this.range = timeSrv.timeRange();
|
||||
}
|
||||
|
||||
PrometheusMetricFindQuery.prototype.process = function() {
|
||||
var label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)$/;
|
||||
var metric_names_regex = /^metrics\((.+)\)$/;
|
||||
var query_result_regex = /^query_result\((.+)\)$/;
|
||||
|
||||
var label_values_query = this.query.match(label_values_regex);
|
||||
if (label_values_query) {
|
||||
if (label_values_query[1]) {
|
||||
return this.labelValuesQuery(label_values_query[2], label_values_query[1]);
|
||||
} else {
|
||||
return this.labelValuesQuery(label_values_query[2], null);
|
||||
}
|
||||
}
|
||||
|
||||
var metric_names_query = this.query.match(metric_names_regex);
|
||||
if (metric_names_query) {
|
||||
return this.metricNameQuery(metric_names_query[1]);
|
||||
}
|
||||
|
||||
var query_result_query = this.query.match(query_result_regex);
|
||||
if (query_result_query) {
|
||||
return this.queryResultQuery(query_result_query[1]);
|
||||
}
|
||||
|
||||
// if query contains full metric name, return metric name and label list
|
||||
return this.metricNameAndLabelsQuery(this.query);
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.labelValuesQuery = function(label, metric) {
|
||||
var url;
|
||||
|
||||
if (!metric) {
|
||||
// return label values globally
|
||||
url = '/api/v1/label/' + label + '/values';
|
||||
|
||||
return this.datasource._request('GET', url).then(function(result) {
|
||||
return _.map(result.data.data, function(value) {
|
||||
return {text: value};
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
url = '/api/v1/series?match[]=' + encodeURIComponent(metric)
|
||||
+ '&start=' + start
|
||||
+ '&end=' + end;
|
||||
|
||||
return this.datasource._request('GET', url)
|
||||
.then(function(result) {
|
||||
var _labels = _.map(result.data.data, function(metric) {
|
||||
return metric[label];
|
||||
});
|
||||
|
||||
return _.uniq(_labels).map(function(metric) {
|
||||
return {
|
||||
text: metric,
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.metricNameQuery = function(metricFilterPattern) {
|
||||
var url = '/api/v1/label/__name__/values';
|
||||
|
||||
return this.datasource._request('GET', url)
|
||||
.then(function(result) {
|
||||
return _.chain(result.data.data)
|
||||
.filter(function(metricName) {
|
||||
var r = new RegExp(metricFilterPattern);
|
||||
return r.test(metricName);
|
||||
})
|
||||
.map(function(matchedMetricName) {
|
||||
return {
|
||||
text: matchedMetricName,
|
||||
expandable: true
|
||||
};
|
||||
})
|
||||
.value();
|
||||
});
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.queryResultQuery = function(query) {
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
return this.datasource.performInstantQuery({ expr: query }, end)
|
||||
.then(function(result) {
|
||||
return _.map(result.data.data.result, function(metricData) {
|
||||
var text = metricData.metric.__name__ || '';
|
||||
delete metricData.metric.__name__;
|
||||
text += '{' +
|
||||
_.map(metricData.metric, function(v, k) { return k + '="' + v + '"'; }).join(',') +
|
||||
'}';
|
||||
text += ' ' + metricData.value[1] + ' ' + metricData.value[0] * 1000;
|
||||
|
||||
return {
|
||||
text: text,
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.metricNameAndLabelsQuery = function(query) {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
var url = '/api/v1/series?match[]=' + encodeURIComponent(query)
|
||||
+ '&start=' + start
|
||||
+ '&end=' + end;
|
||||
|
||||
var self = this;
|
||||
return this.datasource._request('GET', url)
|
||||
.then(function(result) {
|
||||
return _.map(result.data.data, function(metric) {
|
||||
return {
|
||||
text: self.datasource.getOriginalMetricName(metric),
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return PrometheusMetricFindQuery;
|
||||
});
|
147
public/app/plugins/datasource/prometheus/metric_find_query.ts
Normal file
147
public/app/plugins/datasource/prometheus/metric_find_query.ts
Normal file
@ -0,0 +1,147 @@
|
||||
import _ from "lodash";
|
||||
|
||||
export default class PrometheusMetricFindQuery {
|
||||
datasource: any;
|
||||
query: any;
|
||||
range: any;
|
||||
|
||||
constructor(datasource, query, timeSrv) {
|
||||
this.datasource = datasource;
|
||||
this.query = query;
|
||||
this.range = timeSrv.timeRange();
|
||||
}
|
||||
|
||||
process() {
|
||||
var label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)$/;
|
||||
var metric_names_regex = /^metrics\((.+)\)$/;
|
||||
var query_result_regex = /^query_result\((.+)\)$/;
|
||||
|
||||
var label_values_query = this.query.match(label_values_regex);
|
||||
if (label_values_query) {
|
||||
if (label_values_query[1]) {
|
||||
return this.labelValuesQuery(
|
||||
label_values_query[2],
|
||||
label_values_query[1]
|
||||
);
|
||||
} else {
|
||||
return this.labelValuesQuery(label_values_query[2], null);
|
||||
}
|
||||
}
|
||||
|
||||
var metric_names_query = this.query.match(metric_names_regex);
|
||||
if (metric_names_query) {
|
||||
return this.metricNameQuery(metric_names_query[1]);
|
||||
}
|
||||
|
||||
var query_result_query = this.query.match(query_result_regex);
|
||||
if (query_result_query) {
|
||||
return this.queryResultQuery(query_result_query[1]);
|
||||
}
|
||||
|
||||
// if query contains full metric name, return metric name and label list
|
||||
return this.metricNameAndLabelsQuery(this.query);
|
||||
}
|
||||
|
||||
labelValuesQuery(label, metric) {
|
||||
var url;
|
||||
|
||||
if (!metric) {
|
||||
// return label values globally
|
||||
url = "/api/v1/label/" + label + "/values";
|
||||
|
||||
return this.datasource._request("GET", url).then(function(result) {
|
||||
return _.map(result.data.data, function(value) {
|
||||
return { text: value };
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
url =
|
||||
"/api/v1/series?match[]=" +
|
||||
encodeURIComponent(metric) +
|
||||
"&start=" +
|
||||
start +
|
||||
"&end=" +
|
||||
end;
|
||||
|
||||
return this.datasource._request("GET", url).then(function(result) {
|
||||
var _labels = _.map(result.data.data, function(metric) {
|
||||
return metric[label];
|
||||
});
|
||||
|
||||
return _.uniq(_labels).map(function(metric) {
|
||||
return {
|
||||
text: metric,
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
metricNameQuery(metricFilterPattern) {
|
||||
var url = "/api/v1/label/__name__/values";
|
||||
|
||||
return this.datasource._request("GET", url).then(function(result) {
|
||||
return _.chain(result.data.data)
|
||||
.filter(function(metricName) {
|
||||
var r = new RegExp(metricFilterPattern);
|
||||
return r.test(metricName);
|
||||
})
|
||||
.map(function(matchedMetricName) {
|
||||
return {
|
||||
text: matchedMetricName,
|
||||
expandable: true
|
||||
};
|
||||
})
|
||||
.value();
|
||||
});
|
||||
}
|
||||
|
||||
queryResultQuery(query) {
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
return this.datasource
|
||||
.performInstantQuery({ expr: query }, end)
|
||||
.then(function(result) {
|
||||
return _.map(result.data.data.result, function(metricData) {
|
||||
var text = metricData.metric.__name__ || "";
|
||||
delete metricData.metric.__name__;
|
||||
text +=
|
||||
"{" +
|
||||
_.map(metricData.metric, function(v, k) {
|
||||
return k + '="' + v + '"';
|
||||
}).join(",") +
|
||||
"}";
|
||||
text += " " + metricData.value[1] + " " + metricData.value[0] * 1000;
|
||||
|
||||
return {
|
||||
text: text,
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
metricNameAndLabelsQuery(query) {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
var url =
|
||||
"/api/v1/series?match[]=" +
|
||||
encodeURIComponent(query) +
|
||||
"&start=" +
|
||||
start +
|
||||
"&end=" +
|
||||
end;
|
||||
|
||||
var self = this;
|
||||
return this.datasource._request("GET", url).then(function(result) {
|
||||
return _.map(result.data.data, function(metric) {
|
||||
return {
|
||||
text: self.datasource.getOriginalMetricName(metric),
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -1,27 +1,24 @@
|
||||
define([
|
||||
'angular',
|
||||
'jquery',
|
||||
'lodash',
|
||||
], function(angular, jquery, _) {
|
||||
'use strict';
|
||||
import _ from 'lodash';
|
||||
import angular from 'angular';
|
||||
|
||||
var module = angular.module('grafana.controllers');
|
||||
export class SeriesOverridesCtrl {
|
||||
|
||||
module.controller('SeriesOverridesCtrl', function($scope, $element, popoverSrv) {
|
||||
/** @ngInject */
|
||||
constructor($scope, $element, popoverSrv) {
|
||||
$scope.overrideMenu = [];
|
||||
$scope.currentOverrides = [];
|
||||
$scope.override = $scope.override || {};
|
||||
|
||||
$scope.addOverrideOption = function(name, propertyName, values) {
|
||||
var option = {};
|
||||
option.text = name;
|
||||
option.propertyName = propertyName;
|
||||
option.index = $scope.overrideMenu.length;
|
||||
option.values = values;
|
||||
|
||||
option.submenu = _.map(values, function(value) {
|
||||
return { text: String(value), value: value };
|
||||
});
|
||||
var option = {
|
||||
text: name,
|
||||
propertyName: propertyName,
|
||||
index: $scope.overrideMenu.lenght,
|
||||
values: values,
|
||||
submenu: _.map(values, function(value) {
|
||||
return { text: String(value), value: value };
|
||||
})
|
||||
};
|
||||
|
||||
$scope.overrideMenu.push(option);
|
||||
};
|
||||
@ -97,22 +94,24 @@ define([
|
||||
|
||||
$scope.addOverrideOption('Bars', 'bars', [true, false]);
|
||||
$scope.addOverrideOption('Lines', 'lines', [true, false]);
|
||||
$scope.addOverrideOption('Line fill', 'fill', [0,1,2,3,4,5,6,7,8,9,10]);
|
||||
$scope.addOverrideOption('Line width', 'linewidth', [0,1,2,3,4,5,6,7,8,9,10]);
|
||||
$scope.addOverrideOption('Line fill', 'fill', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
$scope.addOverrideOption('Line width', 'linewidth', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
$scope.addOverrideOption('Null point mode', 'nullPointMode', ['connected', 'null', 'null as zero']);
|
||||
$scope.addOverrideOption('Fill below to', 'fillBelowTo', $scope.getSeriesNames());
|
||||
$scope.addOverrideOption('Staircase line', 'steppedLine', [true, false]);
|
||||
$scope.addOverrideOption('Dashes', 'dashes', [true, false]);
|
||||
$scope.addOverrideOption('Dash Length', 'dashLength', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]);
|
||||
$scope.addOverrideOption('Dash Space', 'spaceLength', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]);
|
||||
$scope.addOverrideOption('Dash Length', 'dashLength', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
|
||||
$scope.addOverrideOption('Dash Space', 'spaceLength', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
|
||||
$scope.addOverrideOption('Points', 'points', [true, false]);
|
||||
$scope.addOverrideOption('Points Radius', 'pointradius', [1,2,3,4,5]);
|
||||
$scope.addOverrideOption('Points Radius', 'pointradius', [1, 2, 3, 4, 5]);
|
||||
$scope.addOverrideOption('Stack', 'stack', [true, false, 'A', 'B', 'C', 'D']);
|
||||
$scope.addOverrideOption('Color', 'color', ['change']);
|
||||
$scope.addOverrideOption('Y-axis', 'yaxis', [1, 2]);
|
||||
$scope.addOverrideOption('Z-index', 'zindex', [-3,-2,-1,0,1,2,3]);
|
||||
$scope.addOverrideOption('Z-index', 'zindex', [-3, -2, -1, 0, 1, 2, 3]);
|
||||
$scope.addOverrideOption('Transform', 'transform', ['negative-Y']);
|
||||
$scope.addOverrideOption('Legend', 'legend', [true, false]);
|
||||
$scope.updateCurrentOverrides();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
angular.module('grafana.controllers').controller('SeriesOverridesCtrl', SeriesOverridesCtrl);
|
Loading…
Reference in New Issue
Block a user