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

查看:48
本文介绍了如何使用 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天全站免登陆