API 监控 EC2 实例
API to monitor EC2 instance
CA UIM probe 使用 AWS 提供的 API 监控 EC2 实例。
我可以访问此 AWS API 以监控 EC2 实例吗?
当然,您可以使用 AWS REST API(可通过您提供的文档的 SDKs or CLI). To get instance metrics you'll need to use EC2 and CloudWatch APIs. Here are the examples with AWS CLI for the metrics from "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. Subpages contain available metrics for particular services. Here是 EC2 的页面。
使用您的语言的 SDK 时,您将获得几乎相同的数据。如您所见,CloudWatch 只是 returns 您查询过的带有时间戳的指标列表。
CA UIM probe 使用 AWS 提供的 API 监控 EC2 实例。
我可以访问此 AWS API 以监控 EC2 实例吗?
当然,您可以使用 AWS REST API(可通过您提供的文档的 SDKs or CLI). To get instance metrics you'll need to use EC2 and CloudWatch APIs. Here are the examples with AWS CLI for the metrics from "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. Subpages contain available metrics for particular services. Here是 EC2 的页面。
使用您的语言的 SDK 时,您将获得几乎相同的数据。如您所见,CloudWatch 只是 returns 您查询过的带有时间戳的指标列表。