简体   繁体   中英

boto3 get_metric_statistics returning empty datapoints

I'm trying to make a simple python plugin that returns metrics on dynamodb but I can only get it to return an empty datapoint.

#!/usr/bin/env python
import sys
import boto3
import time
import optparse
from pprint import pprint
from datetime import datetime
from datetime import timedelta

def initialize_client():

    client = boto3.client(
        'cloudwatch',
        aws_access_key_id = 'xxxxx',
        aws_secret_access_key = 'xxxxx',
        region_name = 'us-east-2'
    )

    return client    

def request_metric(client):

    response = client.get_metric_statistics(
        Namespace = 'AWS/DynamoDB',
        Period = 120,
        StartTime = datetime.utcnow() - timedelta(days=2),
        EndTime = datetime.utcnow(),
        MetricName = 'ConsumedWriteCapacityUnits',
        Statistics=['Average'],
        Dimensions = [
            {
                'Name': 'TableName',
                'Value': 'test'
            }   
        ],        
    )

    return response    

def main():

    client = initialize_client()

    response = request_metric(client)

    pprint(response)

    return 0

main()

Here is the output I get:

{u'Datapoints': [],
 u'Label': 'ConsumedWriteCapacityUnits',
 'ResponseMetadata': {'HTTPHeaders': {'content-length': '349',
                                      'content-type': 'text/xml',
                                      'date': 'Wed, 22 Aug 2018 20:57:44 GMT',
                                      'x-amzn-requestid': 'xxxxx'},
                      'HTTPStatusCode': 200,
                      'RequestId': 'xxxxx',
                      'RetryAttempts': 0}}

I was able to get it working with RDS but I can't seem to get DynamoDB to return datapoints. What am I missing here?

There was an issue with the start time. Once I set

StartTime = datetime.utcnow() - timedelta(seconds = 600),

to 600 seconds instead of 2 days I was able to get datapoints. Also make sure the region is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM