我编写了一个脚本来不断地将我的所有 S3 存储桶日志文件下拉到我的 Logstash 服务器,因此可以使用此拉取请求中的模式对其进行解析。唉,鉴于脚本从头开始重新创建日志文件,而不是只是附加到它,Logstash 的file
输入没有看到任何新的变化。有任何想法吗?
下面的脚本:
#!/usr/bin/ruby
require 'rubygems'
require 'aws/s3'
# for non-us buckets, we need to change the endpoint
AWS.config(:s3_endpoint => "s3-eu-west-1.amazonaws.com")
# connect to S3
s3 = AWS::S3.new(:access_key_id => S3_ACCESS_KEY, :secret_access_key => S3_SECRET_KEY)
# grab the bucket where the logs are stored
bucket = s3.buckets[BUCKET_NAME]
File.open("/var/log/s3_bucket.log", 'w') do |file|
# grab all the objects in the bucket, can also use a prefix here and limit what S3 returns
bucket.objects.with_prefix('staticassets-logs/').each do |log|
log.read do |line|
file.write(line)
end
end
end
有什么帮助吗?谢谢!