CA UIM probe使用AWS提供的API监控EC2实例 .
我是否可以访问此AWS API以监控EC2实例?
当然,您可以使用AWS REST API(可通过SDKs或CLI获得) . 要获取实例指标,您需要使用EC2和CloudWatch API . 以下是AWS CLI的示例,其中包含您提供的文档"AWS related QOS Metrics"的指标:
Instance State :
aws ec2 describe-instances --instance-ids i-999f9f99f999f99f9 --query "Reservations[*].Instances[*].[State]" [ [ [ { "Code": 16, "Name": "running" } ] ] ]
CPU Utilization (%) :
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "CPUUtilization", "Datapoints": [ { "Timestamp": "2018-12-07T02:40:00Z", "Average": 0.0, "Unit": "Percent" }, { "Timestamp": "2018-12-07T13:35:00Z", "Average": 1.0, "Unit": "Percent" }, … ] }
Disk Read Ops :
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name EBSReadOps --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name DiskReadOps --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "EBSReadOps", "Datapoints": [ { "Timestamp": "2018-12-07T00:25:00Z", "Average": 10.0, "Unit": "Count" }, { "Timestamp": "2018-12-07T20:10:00Z", "Average": 11.5, "Unit": "Count" }, … ] }
Disk Write Ops
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name EBSWriteOps --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name DiskWriteOps --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "EBSWriteOps", "Datapoints": [ { "Timestamp": "2018-12-07T00:25:00Z", "Average": 1229.3, "Unit": "Count" }, { "Timestamp": "2018-12-07T20:10:00Z", "Average": 496.6, "Unit": "Count" }, … ] }
Disk Read Bytes
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name EBSReadBytes --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name DiskReadBytes --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "EBSReadBytes", "Datapoints": [ { "Timestamp": "2018-12-07T00:25:00Z", "Average": 665.6, "Unit": "Count" }, { "Timestamp": "2018-12-07T20:10:00Z", "Average": 200.3, "Unit": "Count" }, … ] }
Disk Write Bytes
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name EBSWriteBytes --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name DiskWriteBytes --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "EBSWriteBytes", "Datapoints": [ { "Timestamp": "2018-12-07T00:25:00Z", "Average": 7026688.0, "Unit": "Count" }, { "Timestamp": "2018-12-07T20:10:00Z", "Average": 7586713.6, "Unit": "Count" }, … ] }
Network In Bytes
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name NetworkIn --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "NetworkIn", "Datapoints": [ { "Timestamp": "2018-12-07T16:10:00Z", "Average": 24489418.6, "Unit": "Bytes" }, { "Timestamp": "2018-12-07T13:50:00Z", "Average": 21305249.0, "Unit": "Bytes" }, … ] }
Network Out Bytes
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name NetworkOut --period 60 --statistics Average --dimensions Name=InstanceId,Value=i-999f9f99f999f99f9 --start-time 2018-12-07T00:00:00 --end-time 2018-12-08T00:00:00 { "Label": "NetworkOut", "Datapoints": [ { "Timestamp": "2018-12-07T16:10:00Z", "Average": 25363795.4, "Unit": "Bytes" }, { "Timestamp": "2018-12-07T13:50:00Z", "Average": 22128487.0, "Unit": "Bytes" }, … ] }
可以在here找到完整的可用指标列表 . 子页面包含特定服务的可用指标 . Here是EC2的页面 .
使用语言SDK时,您将获得几乎相同的数据 . 如您所见,CloudWatch只返回您查询过的带时间戳的指标列表 .
1 回答
当然,您可以使用AWS REST API(可通过SDKs或CLI获得) . 要获取实例指标,您需要使用EC2和CloudWatch API . 以下是AWS CLI的示例,其中包含您提供的文档"AWS related QOS Metrics"的指标:
Instance State :
CPU Utilization (%) :
Disk Read Ops :
Disk Write Ops
Disk Read Bytes
Disk Write Bytes
Network In Bytes
Network Out Bytes
可以在here找到完整的可用指标列表 . 子页面包含特定服务的可用指标 . Here是EC2的页面 .
使用语言SDK时,您将获得几乎相同的数据 . 如您所见,CloudWatch只返回您查询过的带时间戳的指标列表 .