AWS CLI get-metric-statistics

笑着哭i 提交于 2019-12-13 15:44:23

问题


I'm trying to request the CPUUtilization from my ec2 instance and following this Command Reference i'm using the following command

aws cloudwatch get-metric-statistics --metric-name CPUUtilization --start-time 2016-08-08T22:48:00 --end-time 2016-08-08T22:53:00 --period 60 --namespace AWS/EC2 --statistics Maximum --dimensions Name=InstanceId,Value=i-myinstanceid

my response is:

{
    "Datapoints": [
        {
            "Timestamp": "2016-08-08T22:51:00Z",
            "Maximum": 0.17,
            "Unit": "Percent"
        }
    ],
    "Label": "CPUUtilization"
}

but shouldn't this return me Data Points with Timestamp within 1 minute?


回答1:


It is not possible to retrieve actual data points from Amazon CloudWatch.

Instead, CloudWatch provides aggregated metrics over a period of time (eg Average, SampleCount, Sum).

From the CloudWatch documentation:

Amazon CloudWatch aggregates statistics according to the period length that you specify in calls to GetMetricStatistics. You can publish as many data points as you want with the same or similar time stamps. CloudWatch aggregates them by period length when you get statistics about those data points with GetMetricStatistics.

However, as you point out, CloudWatch should be returning multiple values over the given time period.

I took your command and ran it against one of my Instances. I found that, by extending the time range, I could get multiple values returned:

{
    "Datapoints": [
        {
            "Timestamp": "2016-08-08T22:52:00Z", 
            "Maximum": 0.0, 
            "Unit": "Percent"
        }, 
        {
            "Timestamp": "2016-08-08T22:47:00Z", 
            "Maximum": 0.17, 
            "Unit": "Percent"
        }, 
        {
            "Timestamp": "2016-08-08T22:42:00Z", 
            "Maximum": 0.16, 
            "Unit": "Percent"
        }, 
        {
            "Timestamp": "2016-08-08T22:37:00Z", 
            "Maximum": 0.17, 
            "Unit": "Percent"
        }
    ], 
    "Label": "CPUUtilization"
}

Notice that my data points were coming back only every 5 minutes. This is because standard monitoring of Amazon EC2 instances only captures metrics every 5 minutes. To obtain metrics at 1-minute intervals, you will need to Enable Detailed Monitoring. (Additional charges apply.)



来源:https://stackoverflow.com/questions/39029743/aws-cli-get-metric-statistics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!