简体   繁体   English

适用于S3的AWS Cloudwatch监控

[英]AWS Cloudwatch monitoring for S3

Amazon Cloudwatch provides some very useful metrics for monitoring my EC2s, load balancers, elasticache and RDS databases, etc and allows me to set alarms for a whole range of criteria; Amazon Cloudwatch提供了一些非常有用的指标来监视我的EC2,负载均衡器,elasticache和RDS数据库等,并允许我为整个标准设置警报; but is there any way to configure it to monitor my S3s as well? 但是有什么方法可以配置它来监视我的S3吗? Or are there any other monitoring tools (besides simply enabling logging) that will help me monitor the numbers of POST/GET requests and data volumes for my S3 resources? 或者是否有其他监视工具(仅启用日志记录)可以帮助我监视S3资源的POST / GET请求数和数据量? And to provide alarms for thresholds of activity or increased datastorage? 并为活动阈值或数据存储增加提供警报?

AWS S3 is a managed storage service. AWS S3是托管存储服务。 The only metrics available in AWS CloudWatch for S3 are NumberOfObjects and BucketSizeBytes . AWS CloudWatch S3可用的唯一指标是NumberOfObjectsBucketSizeBytes In order to understand your S3 usage better you need to do some extra work. 为了更好地了解S3的用法,您需要做一些额外的工作。

I have recently written an AWS Lambda function to do exactly what you ask for and it's available here: 我最近编写了一个AWS Lambda函数来完全满足您的要求,并且可以在此处使用:

https://github.com/maginetv/s3logs-cloudwatch https://github.com/maginetv/s3logs-cloudwatch

It works by parsing S3 Server side log files and aggregates/exports metrics to AWS Cloudwatch (CloudWatch allows you to publish custom metrics). 它通过解析S3服务器端日志文件并将指标聚合/导出到AWS Cloudwatch(CloudWatch允许您发布自定义指标)来工作。

Example graphs that you will get in AWS CloudWatch after deploying this function on your AWS account are: 在您的AWS账户上部署此功能后,您将在AWS CloudWatch中获得以下示例图:

RestGetObject_RequestCount
RestPutObject_RequestCount
RestHeadObject_RequestCount
BatchDeleteObject_RequestCount
RestPostMultiObjectDelete_RequestCount
RestGetObject_HTTP_2XX_RequestCount
RestGetObject_HTTP_4XX_RequestCount
RestGetObject_HTTP_5XX_RequestCount
+ many others

Since metrics are exported to CloudWatch, you can easily set up alarms for them as well. 由于指标已导出到CloudWatch,因此您也可以轻松为其设置警报。 CloudFormation template is included in GitHub repo and you can deploy this function very quickly to gain visibility into your S3 bucket usage. GitHub存储库中包含CloudFormation模板,您可以非常快速地部署此功能,以了解您的S3存储桶使用情况。

EDIT 2016-12-10: 编辑2016-12-10:

In November 2016 AWS has added extra S3 request metrics in CloudWatch that can be enabled when needed. 2016年11月,AWS在CloudWatch中添加了额外的S3请求指标,可以在需要时启用它。 This includes metrics like AllRequests , GetRequests , PutRequests , DeleteRequests , HeadRequests etc. See Monitoring Metrics with Amazon CloudWatch documentation for more details about this feature. 其中包括AllRequestsGetRequestsPutRequestsDeleteRequestsHeadRequests指标 。有关此功能的更多详细信息,请参阅使用Amazon CloudWatch文档监控指标

I was also unable to find any way to do this with CloudWatch. 我也找不到使用CloudWatch进行此操作的任何方法。 This question from April 2012 was answered by Derek@AWS as not having S3 support in CloudWatch. Derek @ AWS回答了2012年4月的这个问题,因为CloudWatch中没有S3支持。 https://forums.aws.amazon.com/message.jspa?messageID=338089 https://forums.aws.amazon.com/message.jspa?messageID=338089

The only thing I could think of would be to import the S3 access logs to a log service (like Splunk). 我唯一想到的就是将S3访问日志导入到日志服务(如Splunk)。 Then create a custom cloud watch metric where you post the data that you parse from the logs. 然后创建一个自定义云监视指标,在其中发布从日志中解析的数据。 But then you have to filter out the polling of the access logs and… And while you were at it, you could just create the alarms in Splunk instead of in S3. 但是,然后您必须过滤掉访问日志的轮询,然后……在进行访问时,您可以仅在Splunk中而不是在S3中创建警报。

If your use case is to simply alert when you are using it too much, you could set up an account billing alert for your S3 usage. 如果您的用例只是在过量使用时发出警报,则可以针对S3的使用情况设置帐户计费警报。

I think this might depend on where you are looking to track the access from. 我认为这可能取决于您要从哪里跟踪访问。 Ie if you are trying to measure/watch usage of S3 objects from outside http/https requests then Anthony's suggestion if enabling S3 logging and then importing into splunk (or redshift) for analysis might work. 即,如果您尝试从外部http / https请求中测量/监视S3对象的使用,则Anthony的建议是否启用S3日志记录然后导入splunk(或redshift)以进行分析可能有用。 You can also watch billing status on requests every day. 您还可以每天根据请求查看帐单状态。

If trying to guage usage from within your own applications, there are some AWS SDK cloudwatch metrics: 如果尝试从您自己的应用程序内部查看使用情况,则有一些AWS开发工具包cloudwatch指标:

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/metrics/package-summary.html http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/metrics/package-summary.html

and

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/metrics/S3ServiceMetric.html http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/metrics/S3ServiceMetric.html

S3 is a managed service, meaning that you don't need to take action based on system events in order to keep it up and running (as long as you can afford to pay for the service's usage). S3是一项托管服务,这意味着您无需根据系统事件采取任何措施即可使其保持正常运行(只要您有能力负担使用该服务的费用)。 The spirit of CloudWatch is to help with monitoring services that require you to take action in order to keep them running. CloudWatch的精神是帮助监视服务,这些服务要求您采取措施以使其保持运行状态。

For example, EC2 instances (which you manage yourself) typically need monitoring to alert when they're overloaded or when they're underused or else when they crash; 例如,EC2实例(由您自己管理)通常需要监视以提醒它们何时过载,何时未充分使用或崩溃。 at some point action needs to be taken in order to spin up new instances to scale out, spin down unused instances to scale back in, or reboot instances that have crashed. 在某个时候,需要采取措施来扩展新实例以进行扩展,缩减未使用的实例以进行扩展或重新启动已崩溃的实例。 CloudWatch is meant to help you do the job of managing these resources more effectively. CloudWatch旨在帮助您更有效地管理这些资源。

To enable Request and Data transfer metrics in your bucket you can run the below command. 要在您的存储桶中启用请求和数据传输指标 ,您可以运行以下命令。 Be aware that these are paid metrics. 请注意,这些是付费指标。

aws s3api put-bucket-metrics-configuration \
    --bucket YOUR-BUCKET-NAME \
    --metrics-configuration Id=EntireBucket 
    --id EntireBucket 

This tutorial describes how to do it in AWS Console with point and click interface. 本教程介绍了如何在带指向和单击界面的AWS Console中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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