如何在一个CLI命令中获取多个RDS度量,而不是执行各种命令?
示例:
我需要单次调用cli 中的CPU利用率、FreeStorageSpace和FreeableMemory统计信息
我用过:
aws cloudwatch get-metric-statistics --namespace AWS/RDS
--metric-name FreeStorageSpace
--start-time $START
--end-time $END
--period 360
--statistics Average
--dimensions "Name=DBInstanceIdentifier,Value=$Instance_ID"
您可以使用此
aws cloudwatch get-metric-data --cli-input-json file://input.json
其中input.json包含要查询的所有相关名称空间和度量名称。
示例输入.json
{
"MetricDataQueries": [{
"Id": "cpuUtilization",
"MetricStat": {
"Metric": {
"Namespace": "AWS/EC2",
"MetricName": "CPUUtilization",
"Dimensions": [{
"Name": "InstanceId",
"Value": "i-000000"
}]
},
"Period": 60,
"Stat": "Average"
},
"ReturnData": true
},
{
"Id": "networkPacketsOut",
"MetricStat": {
"Metric": {
"Namespace": "AWS/EC2",
"MetricName": "NetworkPacketsOut",
"Dimensions": [{
"Name": "InstanceId",
"Value": "i-000000"
}]
},
"Period": 60,
"Stat": "Average"
},
"ReturnData": true
}
],
"StartTime": "2022-04-01T00:00:00",
"EndTime": "2022-04-30T00:00:00"
}
样本输出
{
"MetricDataResults": [{
"Id": "cpuUtilization",
"Label": "CPUUtilization",
"Timestamps": [
"2022-04-20T01:07:00+00:00",
"2022-04-20T01:02:00+00:00",
"2022-04-20T00:57:00+00:00"
],
"Values": [
0.09945355191256719,
0.13280540890988418,
0.13450128228466757
],
"StatusCode": "Complete"
},
{
"Id": "networkPacketsOut",
"Label": "NetworkPacketsOut",
"Timestamps": [
"2022-04-20T01:07:00+00:00",
"2022-04-20T01:02:00+00:00",
"2022-04-20T00:57:00+00:00"
],
"Values": [
82.4,
86.6,
82.2
],
"StatusCode": "Complete"
}
],
"Messages": []
}
我已经用AWS/EC2进行了测试,因为我的帐户中没有RDS。你可以很好地使用它并替换RDS 的名称空间