diff --git a/public/app/plugins/datasource/prometheus/datasource.js b/public/app/plugins/datasource/prometheus/datasource.js index 3f62279f6c9..3bcf1a46b8e 100644 --- a/public/app/plugins/datasource/prometheus/datasource.js +++ b/public/app/plugins/datasource/prometheus/datasource.js @@ -21,6 +21,7 @@ function (angular, _, moment, dateMath) { this.name = datasource.name; this.supportMetrics = true; this.url = datasource.url; + this.directUrl = datasource.directUrl; this.basicAuth = datasource.basicAuth; this.lastErrors = {}; } diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index f29f5c958a4..fe3894a1ef0 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -110,6 +110,11 @@ ng-change="refreshMetricData()"> +
  • + + + +
  • diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.js b/public/app/plugins/datasource/prometheus/query_ctrl.js index 809531f96ac..8fc9ae0d6a3 100644 --- a/public/app/plugins/datasource/prometheus/query_ctrl.js +++ b/public/app/plugins/datasource/prometheus/query_ctrl.js @@ -14,6 +14,7 @@ function (angular, _) { target.expr = target.expr || ''; target.intervalFactor = target.intervalFactor || 2; + target.prometheusLink = $scope.linkToPrometheus(); $scope.metric = ''; $scope.resolutions = _.map([1,2,3,4,5,10], function(f) { @@ -27,6 +28,7 @@ function (angular, _) { }; $scope.refreshMetricData = function() { + $scope.target.prometheusLink = $scope.linkToPrometheus(); if (!_.isEqual($scope.oldTarget, $scope.target)) { $scope.oldTarget = angular.copy($scope.target); $scope.get_data(); @@ -44,6 +46,21 @@ function (angular, _) { .then(callback); }; + $scope.linkToPrometheus = function() { + var range = Math.ceil(($scope.range.to.valueOf() - $scope.range.from.valueOf()) / 1000); + var endTime = $scope.range.to.utc().format('YYYY-MM-DD HH:MM'); + var expr = { + expr: $scope.target.expr, + range_input: range + 's', + end_input: endTime, + step_input: '', + stacked: $scope.panel.stack, + tab: 0 + }; + var hash = encodeURIComponent(JSON.stringify([expr])); + return $scope.datasource.directUrl + '/graph#' + hash; + }; + $scope.init(); });