diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 3e7d3fb1429..0a08047489e 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -19,11 +19,11 @@ function (angular, _, kbn) { this.name = datasource.name; this.supportMetrics = true; - AWS.config.update({ region: datasource.jsonData.region }); - this.cloudwatch = new AWS.CloudWatch({ + this.defaultRegion = datasource.jsonData.defaultRegion; + this.credentials = { accessKeyId: datasource.jsonData.accessKeyId, - secretAccessKey: datasource.jsonData.secretAccessKey, - }); + secretAccessKey: datasource.jsonData.secretAccessKey + }; } // Called once per panel (graph) @@ -38,6 +38,7 @@ function (angular, _, kbn) { } var query = {}; + query.region = templateSrv.replace(target.region, options.scopedVars); query.namespace = templateSrv.replace(target.namespace, options.scopedVars); query.metricName = templateSrv.replace(target.metricName, options.scopedVars); query.dimensions = _.map(_.keys(target.dimensions), function(key) { @@ -85,6 +86,8 @@ function (angular, _, kbn) { }; CloudWatchDatasource.prototype.performTimeSeriesQuery = function(query, start, end) { + var cloudwatch = this.getCloudWatchClient(query.region); + var params = { Namespace: query.namespace, MetricName: query.metricName, @@ -96,7 +99,7 @@ function (angular, _, kbn) { }; var d = $q.defer(); - this.cloudwatch.getMetricStatistics(params, function(err, data) { + cloudwatch.getMetricStatistics(params, function(err, data) { if (err) { return d.reject(err); } @@ -106,10 +109,12 @@ function (angular, _, kbn) { return d.promise; }; - CloudWatchDatasource.prototype.performSuggestQuery = function(params) { + CloudWatchDatasource.prototype.performSuggestQuery = function(region, params) { + var cloudwatch = this.getCloudWatchClient(region); + var d = $q.defer(); - this.cloudwatch.listMetrics(params, function(err, data) { + cloudwatch.listMetrics(params, function(err, data) { if (err) { return d.reject(err); } @@ -126,6 +131,18 @@ function (angular, _, kbn) { }); }; + CloudWatchDatasource.prototype.getCloudWatchClient = function(region) { + return new AWS.CloudWatch({ + region: region, + accessKeyId: this.credentials.accessKeyId, + secretAccessKey: this.credentials.secretAccessKey + }); + }; + + CloudWatchDatasource.prototype.getDefaultRegion = function() { + return this.defaultRegion; + }; + function transformMetricData(md, options) { var result = []; diff --git a/public/app/plugins/datasource/cloudwatch/partials/config.html b/public/app/plugins/datasource/cloudwatch/partials/config.html index 9cfcb2f4909..476e75f6e64 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/config.html +++ b/public/app/plugins/datasource/cloudwatch/partials/config.html @@ -3,10 +3,10 @@
diff --git a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html index 53a78895ba8..c279c5b1c78 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/query.editor.html +++ b/public/app/plugins/datasource/cloudwatch/partials/query.editor.html @@ -203,6 +203,20 @@ +
  • + Region +
  • +
  • + +
  • diff --git a/public/app/plugins/datasource/cloudwatch/queryCtrl.js b/public/app/plugins/datasource/cloudwatch/queryCtrl.js index d694f1520dc..cfe14a11b5a 100644 --- a/public/app/plugins/datasource/cloudwatch/queryCtrl.js +++ b/public/app/plugins/datasource/cloudwatch/queryCtrl.js @@ -8,6 +8,17 @@ function (angular, _) { var module = angular.module('grafana.controllers'); /* jshint -W101 */ + var supportedRegion = [ + 'us-east-1', + 'us-west-2', + 'us-west-1', + 'eu-west-1', + 'eu-central-1', + 'ap-southeast-1', + 'ap-southeast-2', + 'ap-northeast-1', + 'sa-east-1', + ]; var supportedMetrics = { "AWS/AutoScaling": [ "GroupMinSize", "GroupMaxSize", "GroupDesiredCapacity", "GroupInServiceInstances", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances" @@ -157,6 +168,7 @@ function (angular, _) { $scope.target.dimensions = $scope.target.dimensions || {}; $scope.target.statistics = $scope.target.statistics || {}; $scope.target.period = $scope.target.period || 60; + $scope.target.region = $scope.target.region || $scope.datasource.getDefaultRegion(); $scope.target.errors = validateTarget(); }; @@ -180,6 +192,10 @@ function (angular, _) { $scope.panel.targets.push(clone); }; + $scope.suggestRegion = function(query, callback) { // jshint unused:false + return supportedRegion; + }; + $scope.suggestNamespace = function(query, callback) { // jshint unused:false return _.keys(supportedMetrics); }; @@ -206,7 +222,7 @@ function (angular, _) { } $scope.datasource - .performSuggestQuery(params) + .performSuggestQuery($scope.target.region, params) .then(function(result) { var suggestData = _.chain(result.Metrics) .map(function(metric) {