CA UIM probe使用AWS提供的API监视EC2实例。
我可以访问此AWS API来监视EC2实例吗?
答案 0 :(得分:2)
当然,您可以使用AWS REST API(可通过SDKs或CLI使用)。要获取实例指标,您需要使用EC2和CloudWatch API。以下是AWS CLI的示例,这些示例针对您提供的文档的"AWS related QOS Metrics"中的指标:
实例状态:
aws ec2 describe-instances --instance-ids i-999f9f99f999f99f9 --query "Reservations[*].Instances[*].[State]"
[
[
[
{
"Code": 16,
"Name": "running"
}
]
]
]
CPU使用率(%):
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"
},
…
]
}
磁盘读取操作:
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"
},
…
]
}
磁盘写入操作
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"
},
…
]
}
磁盘读取字节
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"
},
…
]
}
磁盘写入字节
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"
},
…
]
}
以字节为单位的网络
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"
},
…
]
}
网络输出字节
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只是返回您查询的带有时间戳记的指标的列表。