CloudFront: discrepancy between cache statistics and metrics on CloudWatch

0

We have a bunch of CloudFront distributions, and we need to programmatically access the total bytes transferred (out) for each one of them.

Following the documentation on accessing CloudFront's metrics through CloudWatch via API, we can successfully fetch the BytesDownloaded metric data points we need.

However, we noticed a small but significant discrepancy between that metric and the one visible in che CloudFront console (Reports & analytics > Cache statistics > Bytes transferred to viewers). Specifically, comparing the BytesDownloaded metric fetched through CloudWatch and TotalBytes (from CloudFront popular objects report): the latter is on average a +5-6% bigger than BytesDownloaded (comparing the hourly sum values in the same recent period).

Why is there a discrepancy? How can we access the TotalBytes data points through the API?

Manuel
已提问 1 年前443 查看次数
1 回答
1
已接受的回答

Thank you for the detailed description.


Firstly, TotalBytes is "The total number of bytes that CloudFront served to viewers in response to all requests for the object for all HTTP methods. [1]", while BytesDownloaded is "The total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests. [2]", hence the discrepancy.

Secondly, the popular objects report is currently only available via Console (instead of API.) A workaround would be to enable and leverage CloudFront access logs [3] for your distribution. By using the CloudFront access logs, you could programmatically and periodically analyze access logs to retrieve similar information as the CloudFront popular objects report. Unlike the popular objects report, the access logs are not limited to 50 records, every request to the CloudFront distribution gets logged.


[1] https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/popular-objects-report.html#popular-objects-data

[2] https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/viewing-cloudfront-metrics.html#monitoring-console.distributions

[3] https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html

AWS
weidi
已回答 1 年前
profile pictureAWS
专家
已审核 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则