将日志推送到s3
s3logs的Python项目详细描述
按掩码从目录获取文件并将其推送到s3
安装
pip install s3logs
用法
s3logs config.conf
其中config.conf可以使用该结构:
[S3]access_key=<S3_KEY>secret_key=<S3_SECRET_KEY>host=<s3.example.com>bucket=<bucket_name>chunk_size=<bytes, default=52428800>[logs]suffix=.gzkey_suffix=.gzdirectory=/var/log/nginx/depth=30[map]example.com-access.log=example/accessexample.com-error.log=example/errormysite.me.access.log=mysite/access
当它与该配置一起使用时,脚本将获取目录/var/log/nginx/中的所有文件,只过滤那些以.gz结尾的文件,并根据map将其发送到s3。
例如,/var/log/nginx现在包含:
example.com-access.log example.com-access.log.0.gz example.com-access.log.1.gz example.com-error.log example.com-error.log.0.gz example.com-error.log.1.gz mysite.me.access.log mysite.me.access.log.0.gz mysite.me.error.log mysite.me.error.log.0.gz
所以,如果今天是2015年12月9日,而您的主机名是node1,那么在您的s3上,bucket_name>;就是这些键:
node1/example/access/2015-12-09.gz node1/example/access/2015-12-08.gz node1/example/error/2015-12-09.gz node1/example/error/2015-12-08.gz node1/mysite/access/2015-12-09.gz
因为我们还没有解释如何映射mysite.me.error.log.0.gz—它将被跳过。
脚本还检查文件是否存在于S3中,只推那些文件,而不是。
如果文件名比<;depth>;.gz旧,参数depth将停止推送。