Metrics Insights 示例查询 - Amazon CloudWatch
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

Metrics Insights 示例查询

CloudWatch Metrics Insights 为开放式预览版。预览版面向所有 Amazon 账户开放,您无需请求访问权限。在宣布正式发布之前,可能会添加或更改功能。

本节包含有用的 CloudWatch Metrics Insights 查询的示例,您可以直接复制和使用,或在查询编辑器中复制并修改。控制台中已经提供一些示例,您可以通过选择 Metrics(指标)视图中的 Add query(添加查询)来访问它们。

Application Load Balancer 示例

所有负载均衡器的请求总数

SELECT SUM(RequestCount) FROM SCHEMA("AWS/ApplicationELB", LoadBalancer)

前 10 大最活跃的负载均衡器

SELECT MAX(ActiveConnectionCount) FROM SCHEMA("AWS/ApplicationELB", LoadBalancer) GROUP BY LoadBalancer ORDER BY SUM() DESC LIMIT 10

Amazon API 使用示例

按账户中的调用次数划分,排名前 20 的 Amazon API

SELECT COUNT(CallCount) FROM SCHEMA("AWS/Usage", Class, Resource, Service, Type) WHERE Type = 'API' GROUP BY Service, Resource ORDER BY COUNT() DESC LIMIT 20

按调用排序的 CloudWatch API

SELECT COUNT(CallCount) FROM SCHEMA("AWS/Usage", Class, Resource, Service, Type) WHERE Type = 'API' AND Service = 'CloudWatch' GROUP BY Resource ORDER BY COUNT() DESC

DynamoDB 示例

按消耗的读取数排序的前 10 个表

SELECT SUM(ProvisionedWriteCapacityUnits) FROM SCHEMA("AWS/DynamoDB", TableName) GROUP BY TableName ORDER BY MAX() DESC LIMIT 10

按返回的字节数排序的前 10 个表

SELECT SUM(ReturnedBytes) FROM SCHEMA("AWS/DynamoDB", TableName) GROUP BY TableName ORDER BY MAX() DESC LIMIT 10

按用户错误排序的前 10 个表

SELECT SUM(UserErrors) FROM SCHEMA("AWS/DynamoDB", TableName) GROUP BY TableName ORDER BY MAX() DESC LIMIT 10

Amazon Elastic Block Store 示例

按写入字节数排序的前 10 个 Amazon EBS 卷

SELECT SUM(VolumeWriteBytes) FROM SCHEMA("AWS/EBS", VolumeId) GROUP BY VolumeId ORDER BY SUM() DESC LIMIT 10

Amazon EBS 卷的平均写入时间

SELECT AVG(VolumeTotalWriteTime) FROM SCHEMA("AWS/EBS", VolumeId)

Amazon EC2 示例

按最高排序的 EC2 实例 CPU 使用率

SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/EC2", InstanceId) GROUP BY InstanceId ORDER BY AVG() DESC

整个机群的平均 CPU 使用率

SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/EC2", InstanceId)

按最高 CPU 使用率排序的前 10 个实例

SELECT MAX(CPUUtilization) FROM SCHEMA("AWS/EC2", InstanceId) GROUP BY InstanceId ORDER BY MAX() DESC LIMIT 10

在这种情况下,CloudWatch 代理正在根据应用程序收集 CPUUtilization 指标。此查询筛选特定应用程序名称的此指标的平均值。

SELECT AVG(CPUUtilization) FROM "AWS/CWAgent" WHERE ApplicationName = 'eCommerce'

Amazon Elastic Container Service 示例

所有 ECS 集群的平均 CPU 使用率

SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/ECS", ClusterName)

按内存利用率排序的前 10 个集群

SELECT AVG(MemoryUtilization) FROM SCHEMA("AWS/ECS", ClusterName) GROUP BY ClusterName ORDER BY AVG() DESC LIMIT 10

按 CPU 使用率排序的前 10 项服务

SELECT AVG(CPUUtilization) FROM SCHEMA("AWS/ECS", ClusterName, ServiceName) GROUP BY ClusterName, ServiceName ORDER BY AVG() DESC LIMIT 10

按运行任务排序的前 10 项服务 (Container Insights)

SELECT AVG(RunningTaskCount) FROM SCHEMA("ECS/ContainerInsights", ClusterName, ServiceName) GROUP BY ClusterName, ServiceName ORDER BY AVG() DESC LIMIT 10

Amazon Elastic Kubernetes Service Container Insights 示例

所有 EKS 集群的平均 CPU 使用率

SELECT AVG(pod_cpu_utilization) FROM SCHEMA("ContainerInsights", ClusterName)

按节点 CPU 使用率排序的前 10 个集群

SELECT AVG(node_cpu_utilization) FROM SCHEMA("ContainerInsights", ClusterName) GROUP BY ClusterName ORDER BY AVG() DESC LIMIT 10

按 pod 内存利用率排序的前 10 个集群

SELECT AVG(pop_memory_utilization) FROM SCHEMA("ContainerInsights", ClusterName) GROUP BY ClusterName ORDER BY AVG() DESC LIMIT 10

按 CPU 使用率排序的前 10 个节点

SELECT AVG(node_cpu_utilization) FROM SCHEMA("ContainerInsights", ClusterName, NodeName) GROUP BY ClusterName, NodeName ORDER BY AVG() DESC LIMIT 10

按内存利用率排序的前 10 个 pod

SELECT AVG(pod_memory_utilization) FROM SCHEMA("ContainerInsights", ClusterName, PodName) GROUP BY ClusterName, PodName ORDER BY AVG() DESC LIMIT 10

EventBridge 示例

按调用排序的前 10 条规则

SELECT SUM(Invocations) FROM SCHEMA("AWS/Events", RuleName) GROUP BY RuleName ORDER BY MAX() DESC LIMIT 10

按失败调用排序的前 10 条规则

SELECT SUM(FailedInvocations) FROM SCHEMA("AWS/Events", RuleName) GROUP BY RuleName ORDER BY MAX() DESC LIMIT 10

按匹配规则排序的前 10 条规则

SELECT SUM(MatchedEvents) FROM SCHEMA("AWS/Events", RuleName) GROUP BY RuleName ORDER BY MAX() DESC LIMIT 10

Kinesis 示例

按写入字节数排序的前 10 个流

SELECT SUM("PutRecords.Bytes") FROM SCHEMA("AWS/Kinesis", StreamName) GROUP BY StreamName ORDER BY SUM() DESC LIMIT 10

按流中最早的项目排序的前 10 个流

SELECT MAX("GetRecords.IteratorAgeMilliseconds") FROM SCHEMA("AWS/Kinesis", StreamName) GROUP BY StreamName ORDER BY MAX() DESC LIMIT 10

Lambda 示例

按调用次数排序的 Lambda 函数

SELECT SUM(Invocations) FROM SCHEMA("AWS/Lambda", FunctionName) GROUP BY FunctionName ORDER BY SUM() DESC

按最长运行时排序的前 10 个 Lambda 函数

SELECT AVG(Duration) FROM SCHEMA("AWS/Lambda", FunctionName) GROUP BY FunctionName ORDER BY MAX() DESC LIMIT 10

按错误计数排序的前 10 个 Lambda 函数

SELECT SUM(Errors) FROM SCHEMA("AWS/Lambda", FunctionName) GROUP BY FunctionName ORDER BY SUM() DESC LIMIT 10

CloudWatch Logs 示例

按传入事件排序的前 10 个日志组

SELECT SUM(IncomingLogEvents) FROM SCHEMA("AWS/Logs", LogGroupName) GROUP BY LogGroupName ORDER BY SUM() DESC LIMIT 10

按写入字节数排序的前 10 个日志组

SELECT SUM(IncomingBytes) FROM SCHEMA("AWS/Logs", LogGroupName) GROUP BY LogGroupName ORDER BY SUM() DESC LIMIT 10

Amazon RDS 示例

按最高 CPU 使用率排序的前 10 个 Amazon RDS 实例

SELECT MAX(CPUUtilization) FROM SCHEMA("AWS/RDS", DBInstanceIdentifier) GROUP BY DBInstanceIdentifier ORDER BY MAX() DESC LIMIT 10

按写入数排序的前 10 个 Amazon RDS 集群

SELECT SUM(WriteIOPS) FROM SCHEMA("AWS/RDS", DBClusterIdentifier) GROUP BY DBClusterIdentifier ORDER BY MAX() DESC LIMIT 10

Amazon Simple Storage Service 示例

按存储桶排序的平均延迟

SELECT AVG(TotalRequestLatency) FROM SCHEMA("AWS/S3", BucketName, FilterId) WHERE FilterId = 'EntireBucket' GROUP BY BucketName ORDER BY AVG() DESC

按已下载字节数排序的前 10 个存储桶

SELECT SUM(BytesDownloaded) FROM SCHEMA("AWS/S3", BucketName, FilterId) WHERE FilterId = 'EntireBucket' GROUP BY BucketName ORDER BY SUM() DESC LIMIT 10

Amazon Simple Notification Service 示例

SNS 主题发布的消息总数

SELECT SUM(NumberOfMessagesPublished) FROM SCHEMA("AWS/SNS", TopicName)

按发布消息排序的前 10 个主题

SELECT SUM(NumberOfMessagesPublished) FROM SCHEMA("AWS/SNS", TopicName) GROUP BY TopicName ORDER BY SUM() DESC LIMIT 10

按消息传送失败排序的前 10 个主题

SELECT SUM(NumberOfNotificationsFailed) FROM SCHEMA("AWS/SNS", TopicName) GROUP BY TopicName ORDER BY SUM() DESC LIMIT 10

Amazon SQS 示例

按可见消息数量排序的前 10 个队列

SELECT AVG(ApproximateNumberOfMessagesVisible) FROM SCHEMA("AWS/SQS", QueueName) GROUP BY QueueName ORDER BY AVG() DESC LIMIT 10

前 10 个最活跃的队列

SELECT SUM(NumberOfMessagesSent) FROM SCHEMA("AWS/SQS", QueueName) GROUP BY QueueName ORDER BY SUM() DESC LIMIT 10

按最早消息的时间排序的前 10 个队列

SELECT AVG(ApproximateAgeOfOldestMessage) FROM SCHEMA("AWS/SQS", QueueName) GROUP BY QueueName ORDER BY AVG() DESC LIMIT 10