2

我正在使用 Python3 的 boto3 尝试使用此处记录的 get_metric_statistics 函数从 SQS 的指标中提取数据:

https://boto3.readthedocs.io/en/latest/reference/services/cloudwatch.html#CloudWatch.Client.get_metric_statistics

这是我试图拉它的代码:

import boto3
import sys
from datetime import datetime, timedelta

client = boto3.client('cloudwatch')

response = client.get_metric_statistics(
    Namespace='SQS',
    MetricName='NumberOfEmptyReceives',
    Dimensions=[
        {
            'Name' : 'QueueName',
            'Value' : 'AlertNotifications'
        }
    ],  
    StartTime=datetime.utcnow() - timedelta(seconds=600),
    EndTime=datetime.utcnow(),
    Period=60,
    Statistics=[
        'Sum'
    ]
)

print(response)
sys.exit(0)

我从 API 收到了一个带有 HTTP 状态代码 200 的响应,所以它起作用了,但我没有得到任何数据点。我还仔细检查了我是否使用 boto3.setup_default_session() 调用了正确的配置文件。

我还仔细检查了我的数据是否存在:https ://i.imgur.com/3TS9wD4.png

有人发现我做错了什么吗?

4

2 回答 2

5

命名空间需要以 AWS/ 开头,例如“AWS/SQS”

请参阅:https ://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html

于 2018-05-11T14:05:27.207 回答
0

也给这个东西一个 Unit 参数。如果我的请求中没有包含 Unit,我的一些 cloudwatch 指标没有返回任何内容。

于 2018-04-16T20:48:47.760 回答