如何使用Boto获取实例的最新Cloudwatch指标数据? [英] How do I get the most recent Cloudwatch metric data for an instance using Boto?

查看:101
本文介绍了如何使用Boto获取实例的最新Cloudwatch指标数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个实例(实际上是多个实例,但只有一个实例开始)的CPU使用率的最新数据,但是以下调用未返回任何数据:

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 any data:

cw = boto.cloudwatch.connect_to_region(Region)
cw.get_metric_statistics(
    300,
    datetime.datetime.now() - datetime.timedelta(seconds=600),
    datetime.datetime.now(),
    'CPUUtilization',
    'AWS/EC2',
    'Average',
    dimensions={'InstanceId':['i-11111111']}
    # for stats across multiple instances:
    # dimensions={'InstanceId':['i-11111111', 'i-22222222', 'i-33333333']}
)

关于其他站点指示检查区域正确,检查期间(第一个参数)是否为60的倍数,并且(如果未启用详细监视)大于或等于300。我已经检查了所有这些内容,但仍然没有任何数据。

Various posts on other sites indicate that checking the region is correct, checking that the period (first argument) is a multiple of 60, and (if you don't have detailed monitoring enabled) is greater than or equal to 300. I've checked all these things and I'm still not getting any data.

推荐答案

这是夏令时/时区问题!

This is a daylight savings time / time zone issue!

您需要从Cloudwatch接收统计信息时使用UTC时间:

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']}
   )

通过一些实验,似乎还指定了多个 InstanceId 维度将仅得出最后指定实例的数据(至少在未启用详细监视的情况下)。

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).

这篇关于如何使用Boto获取实例的最新Cloudwatch指标数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆