mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(cloudwatch): contining work on moving hard coded stuff to backend and cleaning up code, #684
This commit is contained in:
@@ -18,197 +18,8 @@ function (angular, _) {
|
||||
this.supportMetrics = true;
|
||||
this.proxyUrl = datasource.url;
|
||||
this.defaultRegion = datasource.jsonData.defaultRegion;
|
||||
|
||||
/* jshint -W101 */
|
||||
|
||||
this.supportedMetrics = {
|
||||
'AWS/AutoScaling': [
|
||||
'GroupMinSize', 'GroupMaxSize', 'GroupDesiredCapacity', 'GroupInServiceInstances', 'GroupPendingInstances', 'GroupStandbyInstances', 'GroupTerminatingInstances', 'GroupTotalInstances'
|
||||
],
|
||||
'AWS/Billing': [
|
||||
'EstimatedCharges'
|
||||
],
|
||||
'AWS/CloudFront': [
|
||||
'Requests', 'BytesDownloaded', 'BytesUploaded', 'TotalErrorRate', '4xxErrorRate', '5xxErrorRate'
|
||||
],
|
||||
'AWS/CloudSearch': [
|
||||
'SuccessfulRequests', 'SearchableDocuments', 'IndexUtilization', 'Partitions'
|
||||
],
|
||||
'AWS/DynamoDB': [
|
||||
'ConditionalCheckFailedRequests', 'ConsumedReadCapacityUnits', 'ConsumedWriteCapacityUnits', 'OnlineIndexConsumedWriteCapacity', 'OnlineIndexPercentageProgress', 'OnlineIndexThrottleEvents', 'ProvisionedReadCapacityUnits', 'ProvisionedWriteCapacityUnits', 'ReadThrottleEvents', 'ReturnedItemCount', 'SuccessfulRequestLatency', 'SystemErrors', 'ThrottledRequests', 'UserErrors', 'WriteThrottleEvents'
|
||||
],
|
||||
'AWS/ElastiCache': [
|
||||
'CPUUtilization', 'SwapUsage', 'FreeableMemory', 'NetworkBytesIn', 'NetworkBytesOut',
|
||||
'BytesUsedForCacheItems', 'BytesReadIntoMemcached', 'BytesWrittenOutFromMemcached', 'CasBadval', 'CasHits', 'CasMisses', 'CmdFlush', 'CmdGet', 'CmdSet', 'CurrConnections', 'CurrItems', 'DecrHits', 'DecrMisses', 'DeleteHits', 'DeleteMisses', 'Evictions', 'GetHits', 'GetMisses', 'IncrHits', 'IncrMisses', 'Reclaimed',
|
||||
'CurrConnections', 'Evictions', 'Reclaimed', 'NewConnections', 'BytesUsedForCache', 'CacheHits', 'CacheMisses', 'ReplicationLag', 'GetTypeCmds', 'SetTypeCmds', 'KeyBasedCmds', 'StringBasedCmds', 'HashBasedCmds', 'ListBasedCmds', 'SetBasedCmds', 'SortedSetBasedCmds', 'CurrItems'
|
||||
],
|
||||
'AWS/EBS': [
|
||||
'VolumeReadBytes', 'VolumeWriteBytes', 'VolumeReadOps', 'VolumeWriteOps', 'VolumeTotalReadTime', 'VolumeTotalWriteTime', 'VolumeIdleTime', 'VolumeQueueLength', 'VolumeThroughputPercentage', 'VolumeConsumedReadWriteOps'
|
||||
],
|
||||
'AWS/EC2': [
|
||||
'CPUCreditUsage', 'CPUCreditBalance', 'CPUUtilization', 'DiskReadOps', 'DiskWriteOps', 'DiskReadBytes', 'DiskWriteBytes', 'NetworkIn', 'NetworkOut', 'StatusCheckFailed', 'StatusCheckFailed_Instance', 'StatusCheckFailed_System'
|
||||
],
|
||||
'AWS/ELB': [
|
||||
'HealthyHostCount', 'UnHealthyHostCount', 'RequestCount', 'Latency', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX', 'BackendConnectionErrors', 'SurgeQueueLength', 'SpilloverCount'
|
||||
],
|
||||
'AWS/ElasticMapReduce': [
|
||||
'CoreNodesPending', 'CoreNodesRunning', 'HBaseBackupFailed', 'HBaseMostRecentBackupDuration', 'HBaseTimeSinceLastSuccessfulBackup', 'HDFSBytesRead', 'HDFSBytesWritten', 'HDFSUtilization', 'IsIdle', 'JobsFailed', 'JobsRunning', 'LiveDataNodes', 'LiveTaskTrackers', 'MapSlotsOpen', 'MissingBlocks', 'ReduceSlotsOpen', 'RemainingMapTasks', 'RemainingMapTasksPerSlot', 'RemainingReduceTasks', 'RunningMapTasks', 'RunningReduceTasks', 'S3BytesRead', 'S3BytesWritten', 'TaskNodesPending', 'TaskNodesRunning', 'TotalLoad'
|
||||
],
|
||||
'AWS/Kinesis': [
|
||||
'PutRecord.Bytes', 'PutRecord.Latency', 'PutRecord.Success', 'PutRecords.Bytes', 'PutRecords.Latency', 'PutRecords.Records', 'PutRecords.Success', 'IncomingBytes', 'IncomingRecords', 'GetRecords.Bytes', 'GetRecords.IteratorAgeMilliseconds', 'GetRecords.Latency', 'GetRecords.Success'
|
||||
],
|
||||
'AWS/ML': [
|
||||
'PredictCount', 'PredictFailureCount'
|
||||
],
|
||||
'AWS/OpsWorks': [
|
||||
'cpu_idle', 'cpu_nice', 'cpu_system', 'cpu_user', 'cpu_waitio', 'load_1', 'load_5', 'load_15', 'memory_buffers', 'memory_cached', 'memory_free', 'memory_swap', 'memory_total', 'memory_used', 'procs'
|
||||
],
|
||||
'AWS/Redshift': [
|
||||
'CPUUtilization', 'DatabaseConnections', 'HealthStatus', 'MaintenanceMode', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'PercentageDiskSpaceUsed', 'ReadIOPS', 'ReadLatency', 'ReadThroughput', 'WriteIOPS', 'WriteLatency', 'WriteThroughput'
|
||||
],
|
||||
'AWS/RDS': [
|
||||
'BinLogDiskUsage', 'CPUUtilization', 'DatabaseConnections', 'DiskQueueDepth', 'FreeableMemory', 'FreeStorageSpace', 'ReplicaLag', 'SwapUsage', 'ReadIOPS', 'WriteIOPS', 'ReadLatency', 'WriteLatency', 'ReadThroughput', 'WriteThroughput', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput'
|
||||
],
|
||||
'AWS/Route53': [
|
||||
'HealthCheckStatus', 'HealthCheckPercentageHealthy'
|
||||
],
|
||||
'AWS/SNS': [
|
||||
'NumberOfMessagesPublished', 'PublishSize', 'NumberOfNotificationsDelivered', 'NumberOfNotificationsFailed'
|
||||
],
|
||||
'AWS/SQS': [
|
||||
'NumberOfMessagesSent', 'SentMessageSize', 'NumberOfMessagesReceived', 'NumberOfEmptyReceives', 'NumberOfMessagesDeleted', 'ApproximateNumberOfMessagesDelayed', 'ApproximateNumberOfMessagesVisible', 'ApproximateNumberOfMessagesNotVisible'
|
||||
],
|
||||
'AWS/S3': [
|
||||
'BucketSizeBytes', 'NumberOfObjects'
|
||||
],
|
||||
'AWS/SWF': [
|
||||
'DecisionTaskScheduleToStartTime', 'DecisionTaskStartToCloseTime', 'DecisionTasksCompleted', 'StartedDecisionTasksTimedOutOnClose', 'WorkflowStartToCloseTime', 'WorkflowsCanceled', 'WorkflowsCompleted', 'WorkflowsContinuedAsNew', 'WorkflowsFailed', 'WorkflowsTerminated', 'WorkflowsTimedOut'
|
||||
],
|
||||
'AWS/StorageGateway': [
|
||||
'CacheHitPercent', 'CachePercentUsed', 'CachePercentDirty', 'CloudBytesDownloaded', 'CloudDownloadLatency', 'CloudBytesUploaded', 'UploadBufferFree', 'UploadBufferPercentUsed', 'UploadBufferUsed', 'QueuedWrites', 'ReadBytes', 'ReadTime', 'TotalCacheSize', 'WriteBytes', 'WriteTime', 'WorkingStorageFree', 'WorkingStoragePercentUsed', 'WorkingStorageUsed', 'CacheHitPercent', 'CachePercentUsed', 'CachePercentDirty', 'ReadBytes', 'ReadTime', 'WriteBytes', 'WriteTime', 'QueuedWrites'
|
||||
],
|
||||
'AWS/WorkSpaces': [
|
||||
'Available', 'Unhealthy', 'ConnectionAttempt', 'ConnectionSuccess', 'ConnectionFailure', 'SessionLaunchTime', 'InSessionLatency', 'SessionDisconnect'
|
||||
],
|
||||
};
|
||||
|
||||
this.supportedDimensions = {
|
||||
'AWS/AutoScaling': [
|
||||
'AutoScalingGroupName'
|
||||
],
|
||||
'AWS/Billing': [
|
||||
'ServiceName', 'LinkedAccount', 'Currency'
|
||||
],
|
||||
'AWS/CloudFront': [
|
||||
'DistributionId', 'Region'
|
||||
],
|
||||
'AWS/CloudSearch': [
|
||||
|
||||
],
|
||||
'AWS/DynamoDB': [
|
||||
'TableName', 'GlobalSecondaryIndexName', 'Operation'
|
||||
],
|
||||
'AWS/ElastiCache': [
|
||||
'CacheClusterId', 'CacheNodeId'
|
||||
],
|
||||
'AWS/EBS': [
|
||||
'VolumeId'
|
||||
],
|
||||
'AWS/EC2': [
|
||||
'AutoScalingGroupName', 'ImageId', 'InstanceId', 'InstanceType'
|
||||
],
|
||||
'AWS/ELB': [
|
||||
'LoadBalancerName', 'AvailabilityZone'
|
||||
],
|
||||
'AWS/ElasticMapReduce': [
|
||||
'ClusterId', 'JobId'
|
||||
],
|
||||
'AWS/Kinesis': [
|
||||
'StreamName'
|
||||
],
|
||||
'AWS/ML': [
|
||||
'MLModelId', 'RequestMode'
|
||||
],
|
||||
'AWS/OpsWorks': [
|
||||
'StackId', 'LayerId', 'InstanceId'
|
||||
],
|
||||
'AWS/Redshift': [
|
||||
'NodeID', 'ClusterIdentifier'
|
||||
],
|
||||
'AWS/RDS': [
|
||||
'DBInstanceIdentifier', 'DatabaseClass', 'EngineName'
|
||||
],
|
||||
'AWS/Route53': [
|
||||
'HealthCheckId'
|
||||
],
|
||||
'AWS/SNS': [
|
||||
'Application', 'Platform', 'TopicName'
|
||||
],
|
||||
'AWS/SQS': [
|
||||
'QueueName'
|
||||
],
|
||||
'AWS/S3': [
|
||||
'BucketName', 'StorageType'
|
||||
],
|
||||
'AWS/SWF': [
|
||||
'Domain', 'ActivityTypeName', 'ActivityTypeVersion'
|
||||
],
|
||||
'AWS/StorageGateway': [
|
||||
'GatewayId', 'GatewayName', 'VolumeId'
|
||||
],
|
||||
'AWS/WorkSpaces': [
|
||||
'DirectoryId', 'WorkspaceId'
|
||||
],
|
||||
};
|
||||
/* jshint +W101 */
|
||||
|
||||
/* load custom metrics definitions */
|
||||
var self = this;
|
||||
$q.all(
|
||||
_.chain(datasource.jsonData.customMetricsAttributes)
|
||||
.reject(function(u) {
|
||||
return _.isEmpty(u);
|
||||
})
|
||||
.map(function(u) {
|
||||
return backendSrv.datasourceRequest({ method: 'GET', url: u });
|
||||
})
|
||||
)
|
||||
.then(function(allResponse) {
|
||||
_.chain(allResponse)
|
||||
.map(function(d) {
|
||||
return d.data.Metrics;
|
||||
})
|
||||
.flatten()
|
||||
.reject(function(metric) {
|
||||
return metric.Namespace.indexOf('AWS/') === 0;
|
||||
})
|
||||
.map(function(metric) {
|
||||
metric.Dimensions = _.chain(metric.Dimensions)
|
||||
.map(function(d) {
|
||||
return d.Name;
|
||||
})
|
||||
.value().sort();
|
||||
return metric;
|
||||
})
|
||||
.uniq(function(metric) {
|
||||
return metric.Namespace + metric.MetricName + metric.Dimensions.join('');
|
||||
})
|
||||
.each(function(metric) {
|
||||
if (!_.has(self.supportedMetrics, metric.Namespace)) {
|
||||
self.supportedMetrics[metric.Namespace] = [];
|
||||
}
|
||||
self.supportedMetrics[metric.Namespace].push(metric.MetricName);
|
||||
|
||||
if (!_.has(self.supportedDimensions, metric.Namespace)) {
|
||||
self.supportedDimensions[metric.Namespace] = [];
|
||||
}
|
||||
|
||||
self.supportedDimensions[metric.Namespace] = _.union(self.supportedDimensions[metric.Namespace], metric.Dimensions);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Called once per panel (graph)
|
||||
CloudWatchDatasource.prototype.query = function(options) {
|
||||
var start = convertToCloudWatchTime(options.range.from);
|
||||
var end = convertToCloudWatchTime(options.range.to);
|
||||
@@ -280,12 +91,16 @@ function (angular, _) {
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getNamespaces = function() {
|
||||
return $q.when(_.keys(this.supportedMetrics));
|
||||
return this.awsRequest({action: '__GetNamespaces'});
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getMetrics = function(namespace) {
|
||||
namespace = templateSrv.replace(namespace);
|
||||
return $q.when(this.supportedMetrics[namespace] || []);
|
||||
return this.awsRequest({
|
||||
action: '__GetMetrics',
|
||||
parameters: {
|
||||
namespace: templateSrv.replace(namespace)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CloudWatchDatasource.prototype.getDimensionKeys = function(namespace) {
|
||||
@@ -342,13 +157,12 @@ function (angular, _) {
|
||||
|
||||
var namespaceQuery = query.match(/^namespaces\(\)/);
|
||||
if (namespaceQuery) {
|
||||
return this.getNamespaces().then(transformSuggestData);
|
||||
return this.getNamespaces();
|
||||
}
|
||||
|
||||
var metricNameQuery = query.match(/^metrics\(([^\)]+?)\)/);
|
||||
if (metricNameQuery) {
|
||||
namespace = templateSrv.replace(metricNameQuery[1]);
|
||||
return this.getMetrics(namespace).then(transformSuggestData);
|
||||
return this.getMetrics(metricNameQuery[1]);
|
||||
}
|
||||
|
||||
var dimensionKeysQuery = query.match(/^dimension_keys\(([^\)]+?)\)/);
|
||||
|
||||
@@ -84,87 +84,79 @@ describe('CloudWatchDatasource', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('When performing CloudWatch metricFindQuery', function() {
|
||||
var requestParams;
|
||||
var response = {
|
||||
Metrics: [
|
||||
{
|
||||
Namespace: 'AWS/EC2',
|
||||
MetricName: 'CPUUtilization',
|
||||
Dimensions: [
|
||||
{
|
||||
Name: 'InstanceId',
|
||||
Value: 'i-12345678'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
ctx.backendSrv.datasourceRequest = function(params) {
|
||||
requestParams = params;
|
||||
return ctx.$q.when({data: response});
|
||||
};
|
||||
});
|
||||
|
||||
describe('regions()', () => {
|
||||
let params, result;
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = args => {
|
||||
params = args;
|
||||
return ctx.$q.when({data: [{text: 'us-east-1'}]});
|
||||
};
|
||||
ctx.ds.metricFindQuery("regions()").then(args => {
|
||||
result = args;
|
||||
function describeMetricFindQuery(query, func) {
|
||||
describe('metricFindQuery ' + query, () => {
|
||||
let scenario: any = {};
|
||||
scenario.setup = setupCallback => {
|
||||
beforeEach(() => {
|
||||
setupCallback();
|
||||
ctx.backendSrv.datasourceRequest = args => {
|
||||
scenario.request = args;
|
||||
return ctx.$q.when({data: scenario.requestResponse });
|
||||
};
|
||||
ctx.ds.metricFindQuery(query).then(args => {
|
||||
scenario.result = args;
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
it('should issue __GetRegions request', () => {
|
||||
expect(result[0].text).to.contain('us-east-1');
|
||||
expect(params.data.action).to.be('__GetRegions');
|
||||
});
|
||||
func(scenario);
|
||||
});
|
||||
}
|
||||
|
||||
describeMetricFindQuery('regions()', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = [{text: 'us-east-1'}];
|
||||
});
|
||||
|
||||
it('should return suggest list for namespace()', function(done) {
|
||||
var query = 'namespaces()';
|
||||
ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
result = result.map(function(v) { return v.text; });
|
||||
expect(result).to.contain('AWS/EC2');
|
||||
done();
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it('should return suggest list for metrics()', function(done) {
|
||||
var query = 'metrics(AWS/EC2)';
|
||||
ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
result = result.map(function(v) { return v.text; });
|
||||
expect(result).to.contain('CPUUtilization');
|
||||
done();
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it('should return suggest list for dimension_keys()', function(done) {
|
||||
var query = 'dimension_keys(AWS/EC2)';
|
||||
ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
result = result.map(function(v) { return v.text; });
|
||||
expect(result).to.contain('InstanceId');
|
||||
done();
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it('should return suggest list for dimension_values()', function(done) {
|
||||
var query = 'dimension_values(us-east-1,AWS/EC2,CPUUtilization)';
|
||||
ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
result = result.map(function(v) { return v.text; });
|
||||
expect(result).to.eql(['i-12345678']);
|
||||
done();
|
||||
});
|
||||
ctx.$rootScope.$apply();
|
||||
it('should call __GetRegions and return result', () => {
|
||||
expect(scenario.result[0].text).to.contain('us-east-1');
|
||||
expect(scenario.request.data.action).to.be('__GetRegions');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('namespaces()', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = [{text: 'AWS/EC2'}];
|
||||
});
|
||||
|
||||
it('should call __GetNamespaces and return result', () => {
|
||||
expect(scenario.result[0].text).to.contain('AWS/EC2');
|
||||
expect(scenario.request.data.action).to.be('__GetNamespaces');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('metrics(AWS/EC2)', scenario => {
|
||||
scenario.setup(() => {
|
||||
scenario.requestResponse = [{text: 'CPUUtilization'}];
|
||||
});
|
||||
|
||||
it('should call __GetMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).to.be('CPUUtilization');
|
||||
expect(scenario.request.data.action).to.be('__GetMetrics');
|
||||
});
|
||||
});
|
||||
|
||||
describe('When performing metricFindQuery', function() {
|
||||
// it('should return suggest list for dimension_keys()', function(done) {
|
||||
// var query = 'dimension_keys(AWS/EC2)';
|
||||
// ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
// result = result.map(function(v) { return v.text; });
|
||||
// expect(result).to.contain('InstanceId');
|
||||
// done();
|
||||
// });
|
||||
// ctx.$rootScope.$apply();
|
||||
// });
|
||||
//
|
||||
// it('should return suggest list for dimension_values()', function(done) {
|
||||
// var query = 'dimension_values(us-east-1,AWS/EC2,CPUUtilization)';
|
||||
// ctx.ds.metricFindQuery(query).then(function(result) {
|
||||
// result = result.map(function(v) { return v.text; });
|
||||
// expect(result).to.eql(['i-12345678']);
|
||||
// done();
|
||||
// });
|
||||
// ctx.$rootScope.$apply();
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user