2015-10-02 04:54:35 -05:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
2017-09-09 14:24:39 -05:00
|
|
|
"context"
|
2016-01-14 04:02:04 -06:00
|
|
|
"time"
|
2015-10-02 04:54:35 -05:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
2015-10-02 04:54:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var metricsMap map[string][]string
|
2015-10-02 13:25:28 -05:00
|
|
|
var dimensionsMap map[string][]string
|
2015-10-02 04:54:35 -05:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
type suggestData struct {
|
|
|
|
Text string
|
|
|
|
Value string
|
|
|
|
}
|
|
|
|
|
2016-01-14 04:02:04 -06:00
|
|
|
type CustomMetricsCache struct {
|
|
|
|
Expire time.Time
|
|
|
|
Cache []string
|
|
|
|
}
|
|
|
|
|
|
|
|
var customMetricsMetricsMap map[string]map[string]map[string]*CustomMetricsCache
|
|
|
|
var customMetricsDimensionsMap map[string]map[string]map[string]*CustomMetricsCache
|
|
|
|
|
2015-10-02 04:54:35 -05:00
|
|
|
func init() {
|
|
|
|
metricsMap = map[string][]string{
|
2016-08-20 07:57:20 -05:00
|
|
|
"AWS/ApiGateway": {"4XXError", "5XXError", "CacheHitCount", "CacheMissCount", "Count", "IntegrationLatency", "Latency"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/ApplicationELB": {"ActiveConnectionCount", "ClientTLSNegotiationErrorCount", "HealthyHostCount", "HTTPCode_ELB_4XX_Count", "HTTPCode_ELB_5XX_Count", "HTTPCode_Target_2XX_Count", "HTTPCode_Target_3XX_Count", "HTTPCode_Target_4XX_Count", "HTTPCode_Target_5XX_Count", "IPv6ProcessedBytes", "IPv6RequestCount", "NewConnectionCount", "ProcessedBytes", "RejectedConnectionCount", "RequestCount", "TargetConnectionErrorCount", "TargetResponseTime", "TargetTLSNegotiationErrorCount", "UnHealthyHostCount"},
|
2016-08-14 06:21:17 -05:00
|
|
|
"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"},
|
2017-05-24 06:24:24 -05:00
|
|
|
"AWS/DMS": {"FreeableMemory", "WriteIOPS", "ReadIOPS", "WriteThroughput", "ReadThroughput", "WriteLatency", "ReadLatency", "SwapUsage", "NetworkTransmitThroughput", "NetworkReceiveThroughput", "FullLoadThroughputBandwidthSource", "FullLoadThroughputBandwidthTarget", "FullLoadThroughputRowsSource", "FullLoadThroughputRowsTarget", "CDCIncomingChanges", "CDCChangesMemorySource", "CDCChangesMemoryTarget", "CDCChangesDiskSource", "CDCChangesDiskTarget", "CDCThroughputBandwidthTarget", "CDCThroughputRowsSource", "CDCThroughputRowsTarget", "CDCLatencySource", "CDCLatencyTarget"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/DynamoDB": {"ConditionalCheckFailedRequests", "ConsumedReadCapacityUnits", "ConsumedWriteCapacityUnits", "OnlineIndexConsumedWriteCapacity", "OnlineIndexPercentageProgress", "OnlineIndexThrottleEvents", "ProvisionedReadCapacityUnits", "ProvisionedWriteCapacityUnits", "ReadThrottleEvents", "ReturnedBytes", "ReturnedItemCount", "ReturnedRecordsCount", "SuccessfulRequestLatency", "SystemErrors", "TimeToLiveDeletedItemCount", "ThrottledRequests", "UserErrors", "WriteThrottleEvents"},
|
2016-08-14 06:21:17 -05:00
|
|
|
"AWS/EBS": {"VolumeReadBytes", "VolumeWriteBytes", "VolumeReadOps", "VolumeWriteOps", "VolumeTotalReadTime", "VolumeTotalWriteTime", "VolumeIdleTime", "VolumeQueueLength", "VolumeThroughputPercentage", "VolumeConsumedReadWriteOps", "BurstBalance"},
|
|
|
|
"AWS/EC2": {"CPUCreditUsage", "CPUCreditBalance", "CPUUtilization", "DiskReadOps", "DiskWriteOps", "DiskReadBytes", "DiskWriteBytes", "NetworkIn", "NetworkOut", "NetworkPacketsIn", "NetworkPacketsOut", "StatusCheckFailed", "StatusCheckFailed_Instance", "StatusCheckFailed_System"},
|
|
|
|
"AWS/EC2Spot": {"AvailableInstancePoolsCount", "BidsSubmittedForCapacity", "EligibleInstancePoolCount", "FulfilledCapacity", "MaxPercentCapacityAllocation", "PendingCapacity", "PercentCapacityAllocation", "TargetCapacity", "TerminatingCapacity"},
|
|
|
|
"AWS/ECS": {"CPUReservation", "MemoryReservation", "CPUUtilization", "MemoryUtilization"},
|
|
|
|
"AWS/EFS": {"BurstCreditBalance", "ClientConnections", "DataReadIOBytes", "DataWriteIOBytes", "MetadataIOBytes", "TotalIOBytes", "PermittedThroughput", "PercentIOLimit"},
|
2017-07-20 07:12:56 -05:00
|
|
|
"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", "EstimatedALBActiveConnectionCount", "EstimatedALBConsumedLCUs", "EstimatedALBNewConnectionCount", "EstimatedProcessedBytes"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/ElastiCache": {
|
2015-12-11 02:21:34 -06:00
|
|
|
"CPUUtilization", "FreeableMemory", "NetworkBytesIn", "NetworkBytesOut", "SwapUsage",
|
2015-10-02 04:54:35 -05:00
|
|
|
"BytesUsedForCacheItems", "BytesReadIntoMemcached", "BytesWrittenOutFromMemcached", "CasBadval", "CasHits", "CasMisses", "CmdFlush", "CmdGet", "CmdSet", "CurrConnections", "CurrItems", "DecrHits", "DecrMisses", "DeleteHits", "DeleteMisses", "Evictions", "GetHits", "GetMisses", "IncrHits", "IncrMisses", "Reclaimed",
|
2015-12-11 02:21:34 -06:00
|
|
|
"BytesUsedForHash", "CmdConfigGet", "CmdConfigSet", "CmdTouch", "CurrConfig", "EvictedUnfetched", "ExpiredUnfetched", "SlabsMoved", "TouchHits", "TouchMisses",
|
|
|
|
"NewConnections", "NewItems", "UnusedMemory",
|
|
|
|
"BytesUsedForCache", "CacheHits", "CacheMisses", "CurrConnections", "Evictions", "HyperLogLogBasedCmds", "NewConnections", "Reclaimed", "ReplicationBytes", "ReplicationLag", "SaveInProgress",
|
|
|
|
"CurrItems", "GetTypeCmds", "HashBasedCmds", "KeyBasedCmds", "ListBasedCmds", "SetBasedCmds", "SetTypeCmds", "SortedSetBasedCmds", "StringBasedCmds",
|
2015-10-02 04:54:35 -05:00
|
|
|
},
|
2016-05-26 21:47:53 -05:00
|
|
|
"AWS/ElasticBeanstalk": {
|
|
|
|
"EnvironmentHealth",
|
|
|
|
"ApplicationLatencyP10", "ApplicationLatencyP50", "ApplicationLatencyP75", "ApplicationLatencyP85", "ApplicationLatencyP90", "ApplicationLatencyP95", "ApplicationLatencyP99", "ApplicationLatencyP99.9",
|
|
|
|
"ApplicationRequests2xx", "ApplicationRequests3xx", "ApplicationRequests4xx", "ApplicationRequests5xx", "ApplicationRequestsTotal",
|
|
|
|
"CPUIdle", "CPUIowait", "CPUIrq", "CPUNice", "CPUSoftirq", "CPUSystem", "CPUUser",
|
|
|
|
"InstanceHealth", "InstancesDegraded", "InstancesInfo", "InstancesNoData", "InstancesOk", "InstancesPending", "InstancesSevere", "InstancesUnknown", "InstancesWarning",
|
|
|
|
"LoadAverage1min", "LoadAverage5min",
|
|
|
|
"RootFilesystemUtil",
|
|
|
|
},
|
2015-12-11 02:21:34 -06:00
|
|
|
"AWS/ElasticMapReduce": {"IsIdle", "JobsRunning", "JobsFailed",
|
|
|
|
"MapTasksRunning", "MapTasksRemaining", "MapSlotsOpen", "RemainingMapTasksPerSlot", "ReduceTasksRunning", "ReduceTasksRemaining", "ReduceSlotsOpen",
|
|
|
|
"CoreNodesRunning", "CoreNodesPending", "LiveDataNodes", "TaskNodesRunning", "TaskNodesPending", "LiveTaskTrackers",
|
|
|
|
"S3BytesWritten", "S3BytesRead", "HDFSUtilization", "HDFSBytesRead", "HDFSBytesWritten", "MissingBlocks", "TotalLoad",
|
|
|
|
"BackupFailed", "MostRecentBackupDuration", "TimeSinceLastSuccessfulBackup",
|
|
|
|
"IsIdle", "ContainerAllocated", "ContainerReserved", "ContainerPending", "AppsCompleted", "AppsFailed", "AppsKilled", "AppsPending", "AppsRunning", "AppsSubmitted",
|
|
|
|
"CoreNodesRunning", "CoreNodesPending", "LiveDataNodes", "MRTotalNodes", "MRActiveNodes", "MRLostNodes", "MRUnhealthyNodes", "MRDecommissionedNodes", "MRRebootedNodes",
|
|
|
|
"S3BytesWritten", "S3BytesRead", "HDFSUtilization", "HDFSBytesRead", "HDFSBytesWritten", "MissingBlocks", "CorruptBlocks", "TotalLoad", "MemoryTotalMB", "MemoryReservedMB", "MemoryAvailableMB", "MemoryAllocatedMB", "PendingDeletionBlocks", "UnderReplicatedBlocks", "DfsPendingReplicationBlocks", "CapacityRemainingGB",
|
|
|
|
"HbaseBackupFailed", "MostRecentBackupDuration", "TimeSinceLastSuccessfulBackup"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/ES": {"ClusterStatus.green", "ClusterStatus.yellow", "ClusterStatus.red", "ClusterUsedSpace", "Nodes", "SearchableDocuments", "DeletedDocuments", "CPUCreditBalance", "CPUUtilization", "FreeStorageSpace", "JVMMemoryPressure", "AutomatedSnapshotFailure", "MasterCPUCreditBalance", "MasterCPUUtilization", "MasterFreeStorageSpace", "MasterJVMMemoryPressure", "ReadLatency", "WriteLatency", "ReadThroughput", "WriteThroughput", "DiskQueueDepth", "ReadIOPS", "WriteIOPS"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"AWS/Events": {"Invocations", "FailedInvocations", "TriggeredRules", "MatchedEvents", "ThrottledRules"},
|
|
|
|
"AWS/Firehose": {"DeliveryToElasticsearch.Bytes", "DeliveryToElasticsearch.Records", "DeliveryToElasticsearch.Success", "DeliveryToRedshift.Bytes", "DeliveryToRedshift.Records", "DeliveryToRedshift.Success", "DeliveryToS3.Bytes", "DeliveryToS3.DataFreshness", "DeliveryToS3.Records", "DeliveryToS3.Success", "IncomingBytes", "IncomingRecords", "DescribeDeliveryStream.Latency", "DescribeDeliveryStream.Requests", "ListDeliveryStreams.Latency", "ListDeliveryStreams.Requests", "PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Requests", "PutRecordBatch.Bytes", "PutRecordBatch.Latency", "PutRecordBatch.Records", "PutRecordBatch.Requests", "UpdateDeliveryStream.Latency", "UpdateDeliveryStream.Requests"},
|
|
|
|
"AWS/IoT": {"PublishIn.Success", "PublishOut.Success", "Subscribe.Success", "Ping.Success", "Connect.Success", "GetThingShadow.Accepted"},
|
|
|
|
"AWS/Kinesis": {"GetRecords.Bytes", "GetRecords.IteratorAge", "GetRecords.IteratorAgeMilliseconds", "GetRecords.Latency", "GetRecords.Records", "GetRecords.Success", "IncomingBytes", "IncomingRecords", "PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Success", "PutRecords.Bytes", "PutRecords.Latency", "PutRecords.Records", "PutRecords.Success", "ReadProvisionedThroughputExceeded", "WriteProvisionedThroughputExceeded", "IteratorAgeMilliseconds", "OutgoingBytes", "OutgoingRecords"},
|
2016-09-13 02:08:33 -05:00
|
|
|
"AWS/KinesisAnalytics": {"Bytes", "MillisBehindLatest", "Records", "Success"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/Lambda": {"Invocations", "Errors", "Duration", "Throttles", "IteratorAge"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"AWS/Logs": {"IncomingBytes", "IncomingLogEvents", "ForwardedBytes", "ForwardedLogEvents", "DeliveryErrors", "DeliveryThrottling"},
|
|
|
|
"AWS/ML": {"PredictCount", "PredictFailureCount"},
|
2017-09-08 02:04:15 -05:00
|
|
|
"AWS/NATGateway": {"PacketsOutToDestination", "PacketsOutToSource", "PacketsInFromSource", "PacketsInFromDestination", "BytesOutToDestination", "BytesOutToSource", "BytesInFromSource", "BytesInFromDestination", "ErrorPortAllocation", "ActiveConnectionCount", "ConnectionAttemptCount", "ConnectionEstablishedCount", "IdleTimeoutCount", "PacketsDropCount"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"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"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/RDS": {"ActiveTransactions", "AuroraBinlogReplicaLag", "AuroraReplicaLag", "AuroraReplicaLagMaximum", "AuroraReplicaLagMinimum", "BinLogDiskUsage", "BlockedTransactions", "BufferCacheHitRatio", "CommitLatency", "CommitThroughput", "BinLogDiskUsage", "CPUCreditBalance", "CPUCreditUsage", "CPUUtilization", "DatabaseConnections", "DDLLatency", "DDLThroughput", "Deadlocks", "DeleteLatency", "DeleteThroughput", "DiskQueueDepth", "DMLLatency", "DMLThroughput", "EngineUptime", "FailedSqlStatements", "FreeableMemory", "FreeLocalStorage", "FreeStorageSpace", "InsertLatency", "InsertThroughput", "LoginFailures", "NetworkReceiveThroughput", "NetworkTransmitThroughput", "NetworkThroughput", "Queries", "ReadIOPS", "ReadLatency", "ReadThroughput", "ReplicaLag", "ResultSetCacheHitRatio", "SelectLatency", "SelectThroughput", "SwapUsage", "TotalConnections", "UpdateLatency", "UpdateThroughput", "VolumeBytesUsed", "VolumeReadIOPS", "VolumeWriteIOPS", "WriteIOPS", "WriteLatency", "WriteThroughput"},
|
|
|
|
"AWS/Route53": {"ChildHealthCheckHealthyCount", "HealthCheckStatus", "HealthCheckPercentageHealthy", "ConnectionTime", "SSLHandshakeTime", "TimeToFirstByte"},
|
2017-03-20 03:09:08 -05:00
|
|
|
"AWS/S3": {"BucketSizeBytes", "NumberOfObjects", "AllRequests", "GetRequests", "PutRequests", "DeleteRequests", "HeadRequests", "PostRequests", "ListRequests", "BytesDownloaded", "BytesUploaded", "4xxErrors", "5xxErrors", "FirstByteLatency", "TotalRequestLatency"},
|
2017-02-15 01:12:24 -06:00
|
|
|
"AWS/SES": {"Bounce", "Complaint", "Delivery", "Reject", "Send"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"AWS/SNS": {"NumberOfMessagesPublished", "PublishSize", "NumberOfNotificationsDelivered", "NumberOfNotificationsFailed"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/SQS": {"NumberOfMessagesSent", "SentMessageSize", "NumberOfMessagesReceived", "NumberOfEmptyReceives", "NumberOfMessagesDeleted", "ApproximateAgeOfOldestMessage", "ApproximateNumberOfMessagesDelayed", "ApproximateNumberOfMessagesVisible", "ApproximateNumberOfMessagesNotVisible"},
|
2015-12-11 02:21:34 -06:00
|
|
|
"AWS/StorageGateway": {"CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "CloudBytesDownloaded", "CloudDownloadLatency", "CloudBytesUploaded", "UploadBufferFree", "UploadBufferPercentUsed", "UploadBufferUsed", "QueuedWrites", "ReadBytes", "ReadTime", "TotalCacheSize", "WriteBytes", "WriteTime", "TimeSinceLastRecoveryPoint", "WorkingStorageFree", "WorkingStoragePercentUsed", "WorkingStorageUsed",
|
|
|
|
"CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "ReadBytes", "ReadTime", "WriteBytes", "WriteTime", "QueuedWrites"},
|
2016-06-29 00:11:01 -05:00
|
|
|
"AWS/SWF": {"DecisionTaskScheduleToStartTime", "DecisionTaskStartToCloseTime", "DecisionTasksCompleted", "StartedDecisionTasksTimedOutOnClose", "WorkflowStartToCloseTime", "WorkflowsCanceled", "WorkflowsCompleted", "WorkflowsContinuedAsNew", "WorkflowsFailed", "WorkflowsTerminated", "WorkflowsTimedOut",
|
|
|
|
"ActivityTaskScheduleToCloseTime", "ActivityTaskScheduleToStartTime", "ActivityTaskStartToCloseTime", "ActivityTasksCanceled", "ActivityTasksCompleted", "ActivityTasksFailed", "ScheduledActivityTasksTimedOutOnClose", "ScheduledActivityTasksTimedOutOnStart", "StartedActivityTasksTimedOutOnClose", "StartedActivityTasksTimedOutOnHeartbeat"},
|
2017-06-04 07:24:04 -05:00
|
|
|
"AWS/VPN": {"TunnelState", "TunnelDataIn", "TunnelDataOut"},
|
2017-09-01 03:43:23 -05:00
|
|
|
"WAF": {"AllowedRequests", "BlockedRequests", "CountedRequests"},
|
2015-12-11 02:21:34 -06:00
|
|
|
"AWS/WorkSpaces": {"Available", "Unhealthy", "ConnectionAttempt", "ConnectionSuccess", "ConnectionFailure", "SessionLaunchTime", "InSessionLatency", "SessionDisconnect"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"KMS": {"SecondsUntilKeyMaterialExpiration"},
|
2015-10-02 13:25:28 -05:00
|
|
|
}
|
|
|
|
dimensionsMap = map[string][]string{
|
2016-08-20 07:57:20 -05:00
|
|
|
"AWS/ApiGateway": {"ApiName", "Method", "Resource", "Stage"},
|
2016-08-14 06:21:17 -05:00
|
|
|
"AWS/ApplicationELB": {"LoadBalancer", "TargetGroup", "AvailabilityZone"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/AutoScaling": {"AutoScalingGroupName"},
|
|
|
|
"AWS/Billing": {"ServiceName", "LinkedAccount", "Currency"},
|
|
|
|
"AWS/CloudFront": {"DistributionId", "Region"},
|
|
|
|
"AWS/CloudSearch": {},
|
2017-05-24 06:24:24 -05:00
|
|
|
"AWS/DMS": {"ReplicationInstanceIdentifier", "ReplicationTaskIdentifier"},
|
2016-06-22 21:24:21 -05:00
|
|
|
"AWS/DynamoDB": {"TableName", "GlobalSecondaryIndexName", "Operation", "StreamLabel"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/EBS": {"VolumeId"},
|
|
|
|
"AWS/EC2": {"AutoScalingGroupName", "ImageId", "InstanceId", "InstanceType"},
|
2016-06-28 23:55:16 -05:00
|
|
|
"AWS/EC2Spot": {"AvailabilityZone", "FleetRequestId", "InstanceType"},
|
2016-06-29 00:11:01 -05:00
|
|
|
"AWS/ECS": {"ClusterName", "ServiceName"},
|
2016-06-28 23:55:16 -05:00
|
|
|
"AWS/EFS": {"FileSystemId"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/ELB": {"LoadBalancerName", "AvailabilityZone"},
|
2016-06-29 00:11:01 -05:00
|
|
|
"AWS/ElastiCache": {"CacheClusterId", "CacheNodeId"},
|
2016-05-26 21:47:53 -05:00
|
|
|
"AWS/ElasticBeanstalk": {"EnvironmentName", "InstanceId"},
|
2015-12-11 02:21:34 -06:00
|
|
|
"AWS/ElasticMapReduce": {"ClusterId", "JobFlowId", "JobId"},
|
2016-05-04 03:47:35 -05:00
|
|
|
"AWS/ES": {"ClientId", "DomainName"},
|
2016-03-10 21:11:01 -06:00
|
|
|
"AWS/Events": {"RuleName"},
|
2017-01-28 01:30:57 -06:00
|
|
|
"AWS/Firehose": {"DeliveryStreamName"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"AWS/IoT": {"Protocol"},
|
2016-04-20 00:33:08 -05:00
|
|
|
"AWS/Kinesis": {"StreamName", "ShardID"},
|
2016-09-13 02:08:33 -05:00
|
|
|
"AWS/KinesisAnalytics": {"Flow", "Id", "Application"},
|
2016-06-22 21:24:21 -05:00
|
|
|
"AWS/Lambda": {"FunctionName", "Resource", "Version", "Alias"},
|
2016-03-10 21:11:01 -06:00
|
|
|
"AWS/Logs": {"LogGroupName", "DestinationType", "FilterName"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/ML": {"MLModelId", "RequestMode"},
|
2017-09-08 02:04:15 -05:00
|
|
|
"AWS/NATGateway": {"NatGatewayId"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/OpsWorks": {"StackId", "LayerId", "InstanceId"},
|
|
|
|
"AWS/Redshift": {"NodeID", "ClusterIdentifier"},
|
2017-09-20 01:31:54 -05:00
|
|
|
"AWS/RDS": {"DBInstanceIdentifier", "DBClusterIdentifier", "DbClusterIdentifier", "DatabaseClass", "EngineName", "Role"},
|
2017-06-08 00:01:33 -05:00
|
|
|
"AWS/Route53": {"HealthCheckId", "Region"},
|
2017-03-20 03:09:08 -05:00
|
|
|
"AWS/S3": {"BucketName", "StorageType", "FilterId"},
|
2017-02-15 01:12:24 -06:00
|
|
|
"AWS/SES": {},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/SNS": {"Application", "Platform", "TopicName"},
|
|
|
|
"AWS/SQS": {"QueueName"},
|
|
|
|
"AWS/StorageGateway": {"GatewayId", "GatewayName", "VolumeId"},
|
2016-06-29 00:11:01 -05:00
|
|
|
"AWS/SWF": {"Domain", "WorkflowTypeName", "WorkflowTypeVersion", "ActivityTypeName", "ActivityTypeVersion"},
|
2017-06-04 07:24:04 -05:00
|
|
|
"AWS/VPN": {"VpnId", "TunnelIpAddress"},
|
2017-09-01 03:43:23 -05:00
|
|
|
"WAF": {"Rule", "WebACL"},
|
2015-10-08 10:30:13 -05:00
|
|
|
"AWS/WorkSpaces": {"DirectoryId", "WorkspaceId"},
|
2016-09-12 09:47:31 -05:00
|
|
|
"KMS": {"KeyId"},
|
2015-10-02 04:54:35 -05:00
|
|
|
}
|
2016-01-14 04:02:04 -06:00
|
|
|
|
|
|
|
customMetricsMetricsMap = make(map[string]map[string]map[string]*CustomMetricsCache)
|
|
|
|
customMetricsDimensionsMap = make(map[string]map[string]map[string]*CustomMetricsCache)
|
2015-10-02 04:54:35 -05:00
|
|
|
}
|
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
func (e *CloudWatchExecutor) executeMetricFindQuery(ctx context.Context, queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) *tsdb.BatchResult {
|
|
|
|
result := &tsdb.BatchResult{
|
|
|
|
QueryResults: make(map[string]*tsdb.QueryResult),
|
2016-02-11 09:26:48 -06:00
|
|
|
}
|
2017-09-09 14:24:39 -05:00
|
|
|
queryResult := &tsdb.QueryResult{Meta: simplejson.New(), RefId: queries[0].RefId}
|
|
|
|
|
|
|
|
parameters := queries[0].Model.Get("parameters")
|
|
|
|
subType := queries[0].Model.Get("subtype").MustString()
|
|
|
|
var data []suggestData
|
|
|
|
var err error
|
|
|
|
switch subType {
|
|
|
|
case "regions":
|
|
|
|
data, err = e.handleGetRegions(ctx, parameters, queryContext)
|
|
|
|
if err != nil {
|
|
|
|
queryResult.Error = err
|
2016-01-14 04:02:04 -06:00
|
|
|
}
|
2017-09-09 14:24:39 -05:00
|
|
|
break
|
2015-10-02 04:54:35 -05:00
|
|
|
}
|
2017-09-09 14:24:39 -05:00
|
|
|
transformToTable(data, queryResult)
|
|
|
|
result.QueryResults[queries[0].RefId] = queryResult
|
|
|
|
return result
|
2015-10-02 04:54:35 -05:00
|
|
|
}
|
2015-10-02 13:25:28 -05:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
func transformToTable(data []suggestData, result *tsdb.QueryResult) {
|
|
|
|
table := &tsdb.Table{
|
|
|
|
Columns: make([]tsdb.TableColumn, 2),
|
|
|
|
Rows: make([]tsdb.RowValues, 0),
|
2015-10-02 13:25:28 -05:00
|
|
|
}
|
2017-09-09 14:24:39 -05:00
|
|
|
table.Columns[0].Text = "text"
|
|
|
|
table.Columns[1].Text = "value"
|
|
|
|
|
|
|
|
for _, r := range data {
|
|
|
|
values := make([]interface{}, 2)
|
|
|
|
values[0] = r.Text
|
|
|
|
values[1] = r.Value
|
|
|
|
table.Rows = append(table.Rows, values)
|
2015-10-02 13:25:28 -05:00
|
|
|
}
|
2017-09-09 14:24:39 -05:00
|
|
|
result.Tables = append(result.Tables, table)
|
|
|
|
result.Meta.Set("rowCount", len(data))
|
2015-10-02 13:25:28 -05:00
|
|
|
}
|
2016-01-14 04:02:04 -06:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
// Whenever this list is updated, frontend list should also be updated.
|
|
|
|
// Please update the region list in public/app/plugins/datasource/cloudwatch/partials/config.html
|
|
|
|
func (e *CloudWatchExecutor) handleGetRegions(ctx context.Context, parameters *simplejson.Json, queryContext *tsdb.QueryContext) ([]suggestData, error) {
|
|
|
|
regions := []string{
|
|
|
|
"ap-northeast-1", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-south-1", "ca-central-1", "cn-north-1",
|
|
|
|
"eu-central-1", "eu-west-1", "eu-west-2", "sa-east-1", "us-east-1", "us-east-2", "us-gov-west-1", "us-west-1", "us-west-2",
|
2017-09-01 00:24:05 -05:00
|
|
|
}
|
2016-01-14 04:02:04 -06:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
result := make([]suggestData, 0)
|
|
|
|
for _, region := range regions {
|
|
|
|
result = append(result, suggestData{Text: region, Value: region})
|
2016-01-14 04:02:04 -06:00
|
|
|
}
|
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
return result, nil
|
2016-01-14 04:02:04 -06:00
|
|
|
}
|
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
//func handleGetNamespaces(req *cwRequest, c *middleware.Context) {
|
|
|
|
// keys := []string{}
|
|
|
|
// for key := range metricsMap {
|
|
|
|
// keys = append(keys, key)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// customNamespaces := req.DataSource.JsonData.Get("customMetricsNamespaces").MustString()
|
|
|
|
// if customNamespaces != "" {
|
|
|
|
// for _, key := range strings.Split(customNamespaces, ",") {
|
|
|
|
// keys = append(keys, key)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// sort.Sort(sort.StringSlice(keys))
|
|
|
|
//
|
|
|
|
// result := []interface{}{}
|
|
|
|
// for _, key := range keys {
|
|
|
|
// result = append(result, util.DynMap{"text": key, "value": key})
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// c.JSON(200, result)
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func handleGetMetrics(req *cwRequest, c *middleware.Context) {
|
|
|
|
// reqParam := &struct {
|
|
|
|
// Parameters struct {
|
|
|
|
// Namespace string `json:"namespace"`
|
|
|
|
// } `json:"parameters"`
|
|
|
|
// }{}
|
|
|
|
//
|
|
|
|
// json.Unmarshal(req.Body, reqParam)
|
|
|
|
//
|
|
|
|
// var namespaceMetrics []string
|
|
|
|
// if !isCustomMetrics(reqParam.Parameters.Namespace) {
|
|
|
|
// var exists bool
|
|
|
|
// if namespaceMetrics, exists = metricsMap[reqParam.Parameters.Namespace]; !exists {
|
|
|
|
// c.JsonApiErr(404, "Unable to find namespace "+reqParam.Parameters.Namespace, nil)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// var err error
|
|
|
|
// cwData := req.GetDatasourceInfo()
|
|
|
|
// cwData.Namespace = reqParam.Parameters.Namespace
|
|
|
|
//
|
|
|
|
// if namespaceMetrics, err = getMetricsForCustomMetrics(cwData, getAllMetrics); err != nil {
|
|
|
|
// c.JsonApiErr(500, "Unable to call AWS API", err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// sort.Sort(sort.StringSlice(namespaceMetrics))
|
|
|
|
//
|
|
|
|
// result := []interface{}{}
|
|
|
|
// for _, name := range namespaceMetrics {
|
|
|
|
// result = append(result, util.DynMap{"text": name, "value": name})
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// c.JSON(200, result)
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func handleGetDimensions(req *cwRequest, c *middleware.Context) {
|
|
|
|
// reqParam := &struct {
|
|
|
|
// Parameters struct {
|
|
|
|
// Namespace string `json:"namespace"`
|
|
|
|
// } `json:"parameters"`
|
|
|
|
// }{}
|
|
|
|
//
|
|
|
|
// json.Unmarshal(req.Body, reqParam)
|
|
|
|
//
|
|
|
|
// var dimensionValues []string
|
|
|
|
// if !isCustomMetrics(reqParam.Parameters.Namespace) {
|
|
|
|
// var exists bool
|
|
|
|
// if dimensionValues, exists = dimensionsMap[reqParam.Parameters.Namespace]; !exists {
|
|
|
|
// c.JsonApiErr(404, "Unable to find dimension "+reqParam.Parameters.Namespace, nil)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// var err error
|
|
|
|
// dsInfo := req.GetDatasourceInfo()
|
|
|
|
// dsInfo.Namespace = reqParam.Parameters.Namespace
|
|
|
|
//
|
|
|
|
// if dimensionValues, err = getDimensionsForCustomMetrics(dsInfo, getAllMetrics); err != nil {
|
|
|
|
// c.JsonApiErr(500, "Unable to call AWS API", err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// sort.Sort(sort.StringSlice(dimensionValues))
|
|
|
|
//
|
|
|
|
// result := []interface{}{}
|
|
|
|
// for _, name := range dimensionValues {
|
|
|
|
// result = append(result, util.DynMap{"text": name, "value": name})
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// c.JSON(200, result)
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func getAllMetrics(cwData *DatasourceInfo) (cloudwatch.ListMetricsOutput, error) {
|
|
|
|
// creds, err := GetCredentials(cwData)
|
|
|
|
// if err != nil {
|
|
|
|
// return cloudwatch.ListMetricsOutput{}, err
|
|
|
|
// }
|
|
|
|
// cfg := &aws.Config{
|
|
|
|
// Region: aws.String(cwData.Region),
|
|
|
|
// Credentials: creds,
|
|
|
|
// }
|
|
|
|
// sess, err := session.NewSession(cfg)
|
|
|
|
// if err != nil {
|
|
|
|
// return cloudwatch.ListMetricsOutput{}, err
|
|
|
|
// }
|
|
|
|
// svc := cloudwatch.New(sess, cfg)
|
|
|
|
//
|
|
|
|
// params := &cloudwatch.ListMetricsInput{
|
|
|
|
// Namespace: aws.String(cwData.Namespace),
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// var resp cloudwatch.ListMetricsOutput
|
|
|
|
// err = svc.ListMetricsPages(params,
|
|
|
|
// func(page *cloudwatch.ListMetricsOutput, lastPage bool) bool {
|
|
|
|
// metrics.M_Aws_CloudWatch_ListMetrics.Inc(1)
|
|
|
|
// metrics, _ := awsutil.ValuesAtPath(page, "Metrics")
|
|
|
|
// for _, metric := range metrics {
|
|
|
|
// resp.Metrics = append(resp.Metrics, metric.(*cloudwatch.Metric))
|
|
|
|
// }
|
|
|
|
// return !lastPage
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// return resp, err
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return resp, nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//var metricsCacheLock sync.Mutex
|
|
|
|
//
|
|
|
|
//func getMetricsForCustomMetrics(dsInfo *DatasourceInfo, getAllMetrics func(*DatasourceInfo) (cloudwatch.ListMetricsOutput, error)) ([]string, error) {
|
|
|
|
// metricsCacheLock.Lock()
|
|
|
|
// defer metricsCacheLock.Unlock()
|
|
|
|
//
|
|
|
|
// if _, ok := customMetricsMetricsMap[dsInfo.Profile]; !ok {
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile] = make(map[string]map[string]*CustomMetricsCache)
|
|
|
|
// }
|
|
|
|
// if _, ok := customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region]; !ok {
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region] = make(map[string]*CustomMetricsCache)
|
|
|
|
// }
|
|
|
|
// if _, ok := customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace]; !ok {
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace] = &CustomMetricsCache{}
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = make([]string, 0)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Expire.After(time.Now()) {
|
|
|
|
// return customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, nil
|
|
|
|
// }
|
|
|
|
// result, err := getAllMetrics(dsInfo)
|
|
|
|
// if err != nil {
|
|
|
|
// return []string{}, err
|
|
|
|
// }
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = make([]string, 0)
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Expire = time.Now().Add(5 * time.Minute)
|
|
|
|
//
|
|
|
|
// for _, metric := range result.Metrics {
|
|
|
|
// if isDuplicate(customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, *metric.MetricName) {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = append(customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, *metric.MetricName)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return customMetricsMetricsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//var dimensionsCacheLock sync.Mutex
|
|
|
|
//
|
|
|
|
//func getDimensionsForCustomMetrics(dsInfo *DatasourceInfo, getAllMetrics func(*DatasourceInfo) (cloudwatch.ListMetricsOutput, error)) ([]string, error) {
|
|
|
|
// dimensionsCacheLock.Lock()
|
|
|
|
// defer dimensionsCacheLock.Unlock()
|
|
|
|
//
|
|
|
|
// if _, ok := customMetricsDimensionsMap[dsInfo.Profile]; !ok {
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile] = make(map[string]map[string]*CustomMetricsCache)
|
|
|
|
// }
|
|
|
|
// if _, ok := customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region]; !ok {
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region] = make(map[string]*CustomMetricsCache)
|
|
|
|
// }
|
|
|
|
// if _, ok := customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace]; !ok {
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace] = &CustomMetricsCache{}
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = make([]string, 0)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Expire.After(time.Now()) {
|
|
|
|
// return customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, nil
|
|
|
|
// }
|
|
|
|
// result, err := getAllMetrics(dsInfo)
|
|
|
|
// if err != nil {
|
|
|
|
// return []string{}, err
|
|
|
|
// }
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = make([]string, 0)
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Expire = time.Now().Add(5 * time.Minute)
|
|
|
|
//
|
|
|
|
// for _, metric := range result.Metrics {
|
|
|
|
// for _, dimension := range metric.Dimensions {
|
|
|
|
// if isDuplicate(customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, *dimension.Name) {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache = append(customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, *dimension.Name)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return customMetricsDimensionsMap[dsInfo.Profile][dsInfo.Region][dsInfo.Namespace].Cache, nil
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func isDuplicate(nameList []string, target string) bool {
|
|
|
|
// for _, name := range nameList {
|
|
|
|
// if name == target {
|
|
|
|
// return true
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return false
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//func isCustomMetrics(namespace string) bool {
|
|
|
|
// return strings.Index(namespace, "AWS/") != 0
|
|
|
|
//}
|