简体   繁体   English

将 s3 中的自定义日志上传到 cloudwatch 以进行指标监控

[英]upload custom logs in s3 to cloudwatch for metrics monitoring

I created a custom app that automatically uploads logs to s3.我创建了一个自定义应用程序,可以自动将日志上传到 s3。 Is there a way to push those logs to cloudwatch from s3 for analysis and alerting?有没有办法将这些日志从 s3 推送到 cloudwatch 进行分析和警报? I'm aware that I can use a cloudwatch agent to push directly to cloudwatch from the app but there are complications involved in that option.我知道我可以使用 cloudwatch 代理从应用程序直接推送到 cloudwatch,但该选项涉及复杂性。 Thank you!谢谢!

You could probably use Cloudwatch Events to listen to S3 changes.您可能可以使用 Cloudwatch Events 来监听 S3 的变化。 Not sure about if you can get the data from the S3 file, or just a trigger saying that a new log has been added.不确定您是否可以从 S3 文件中获取数据,或者只是一个表明已添加新日志的触发器。

You could also use S3 event notifications ( https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html ) connected either to a lambda or SQS, and from there create the logs to Cloudwatch.您还可以使用连接到 lambda 或 SQS 的 S3 事件通知 ( https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html ),并从那里创建日志到 Cloudwatch。 (similar to what was suggested by @marcin) (类似于@marcin 的建议)

A better solution, but one that is a bit beyond the scope of the question, would be to send your logs through Kinesis Firehose and from there add the Cloudwatch and S3 logs.一个更好的解决方案,但有点超出问题的范围,是通过 Kinesis Firehose 发送您的日志,然后从那里添加 Cloudwatch 和 S3 日志。

I'm not aware of any out-of-the-box mechanism for that provided by AWS.我不知道 AWS 提供的任何开箱即用的机制。 But I think it could be relatively easy to develop .但我认为它可能相对容易开发

Namely, you can create S3 notification for a PUT of a new log file from your app to S3.也就是说,您可以为从您的应用程序到 S3 的新日志文件的 PUT 创建S3 通知 The event would trigger a lambda function .该事件将触发lambda 函数 The function would get the file and using AWS SDK , eg boto3's put_log_events , it would send the log events to CloudWatch logs.该函数将获取文件并使用AWS SDK ,例如 boto3 的put_log_events ,它将日志事件发送到 CloudWatch 日志。

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

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