How do I get the most recent Cloudwatch metric data for an instance using Boto?

前端 未结 3 1633
野性不改
野性不改 2021-02-02 17:17

I\'m trying to get the most recent data for CPU utilization for an instance (actually, several instances, but just one to start with), however the following call doesn\'t return

3条回答
  •  执念已碎
    2021-02-02 18:07

    This is a daylight savings time / time zone issue!

    You need to use UTC time when receiving statistics from Cloudwatch:

        cw = boto.cloudwatch.connect_to_region(Region)
        cw.get_metric_statistics(
            300,
            datetime.datetime.utcnow() - datetime.timedelta(seconds=600),
            datetime.datetime.utcnow(),
            'CPUUtilization',
            'AWS/EC2',
            'Average',
            dimensions={'InstanceId':['i-11111111']}
       )
    

    From some experimentation it also seems that specifying multiple InstanceId dimensions will result in data only for the last specified instance (at least if detailed monitoring is not enabled).

提交回复
热议问题