question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty DataPoints when getting s3 metrics from cloudwatch

See original GitHub issue

Hi, when using boto3 to get s3 metrics i get empty metrics, I get the metrics via list_metrics(), I can see them on CloudWatch AWS Web Console, I’ve tried different time spans (from 1minute to 1 Day) - Always return empty.

Changed the units, the Statistics. bah.

cw = boto3.client('cloudwatch')
cw.get_metric_statistics(Namespace='AWS/S3',MetricName='BucketSizeBytes', StartTime=datetime.utcnow() - timedelta(days=1), EndTime=datetime.utcnow(), Period=86400, Statistics=['Sum'],Unit='Bytes',Dimensions=[{'Name':'BucketName', 'Value':'backup-bucket'}])

OUTPUT:

{u'Datapoints': [],
 u'Label': 'BucketSizeBytes',
 'ResponseMetadata': {'HTTPStatusCode': 200,
  'RequestId': 'a5c04a0e-4579-11e5-ab73-add86b87b8d9'}}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
nihitkaulcommented, May 8, 2016

Ah! Got it to work by trying bigger time window. I had a timespan of 1 day which was working but it stopped and I had to increase it to 2 days.

3reactions
kyleknapcommented, Aug 25, 2015

So here is what I did to get it to work:

from datetime import timedelta
from datetime import datetime

cw = boto3.client('cloudwatch')
bucket = 'mybucketfoo'

response = cw.get_metric_statistics(
    Namespace='AWS/S3',MetricName='BucketSizeBytes',
    StartTime=datetime.utcnow() - timedelta(days=2) ,
    EndTime=datetime.utcnow(), Period=86400,
    Statistics=['Average'], Unit='Bytes',
    Dimensions=[
        {'Name': 'BucketName', 'Value': bucket},
        {u'Name': 'StorageType', u'Value': 'StandardStorage'}
    ])


print(response)

The important points are that you need to take from this is: the second StorageType dimension and the start date needs to be more than one day from the current time. I could not find too much documentation in the CloudWatch docs about it. However based on the console, you need that StorageType as well to correctly view the data points. Also, the data point, for me, is delivered daily at 12 AM so my guess the range of a day you specified was too small. However, I was not able to find the official minimum span that you must specify.

Let me know if you have any more questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why isn't my CloudWatch GetMetricStatistics API call returning ...
My Amazon CloudWatch "GetMetricStatistics" API call isn't returning any data points. However, the data points are available on the ...
Read more >
Empty datapoints received while retrieving AWS S3 Request ...
From AWS Console, I'm able to see datapoints for the same timestamp. I tried increasing the timeframe but it still gibes the same...
Read more >
No data appears: AWS CloudWatch metric streams
Check the Metric Stream metrics under AWS/CloudWatch/MetricStreams namespace. You will see a count of metric updates and errors per Metric Streams. This ...
Read more >
Why is GetMetricStatistics not returning any data points?
... AWS Knowledge Center: https://aws.amazon.com/premiumsupport/knowledge-center/ cloudwatch -getmetricstatistics-dataTruptesh, an AWS Clo...
Read more >
Getting metrics from Amazon CloudWatch with Amazon SDK ...
List Amazon CloudWatch metrics, retrieve alarms for metrics, and get metric statistics using the Amazon SDK for PHP Version 3.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found