简体   繁体   English

[流利]如何以流利的方式解压缩文件

[英][Fluentd]How to Unzip files in fluentd

I am trying to process log files with .gz extension in fluentd using cat_sweep plugin, and failed in my attempt. 我正在尝试使用cat_sweep插件以流利的方式处理扩展名为.gz的日志文件,但在我的尝试中失败了。 As shown in the below config, I am trying to process all files under /opt/logfiles/* location. 如下面的配置所示,我正在尝试处理/ opt / logfiles / *位置下的所有文件。 However when the file format is .gz, cat_sweep is unable to process the file, and starts deleting the file, but if I unzip the file manually inside the /opt/logfiles/ location, cat_sweep is able to process, the file. 但是,当文件格式为.gz时,cat_sweep无法处理该文件,并开始删除该文件,但如果我在/ opt / logfiles / location内手动解压缩该文件,则cat_sweep可以处理该文件。

<source>
   @type cat_sweep
   file_path_with_glob /opt/logfiles/*
   format none
   tag raw.log
   waiting_seconds 0
   remove_after_processing true
   processing_file_suffix .processing
   error_file_suffix .error
   run_interval 5
</source>

So now I need some plugin that can unzip a given file. 所以现在我需要一些可以解压缩给定文件的插件。 I tried searching for plugins that can unzip a zipped file. 我尝试搜索可以解压缩压缩文件的插件。 I came close when I found about the plugin, which acts like a terminal, where I can use something like gzip -d file_path 当我发现插件时,我接近了,它就像一个终端,我可以使用像gzip -d file_path这样的东西

Link to the plugin: 链接到插件:

http://docs.fluentd.org/v0.12/articles/in_exec http://docs.fluentd.org/v0.12/articles/in_exec

But the problem I see here, is that I cannot send the path of the file to be unzipped at run-time. 但我在这里看到的问题是,我无法在运行时发送文件的路径解压缩。

Can someone help me with some pointers? 有人可以帮我提一些指示吗?

Looking at your requirement, you can still achieve it by using in_exec module, What you have to do is, to simply create a shell script which accepts path to look for .gz files and the wildcard pattern to match file names. 查看您的需求,您仍然可以通过使用in_exec模块来实现它,您需要做的是,简单地创建一个shell脚本,该脚本接受查找.gz文件的路径以及匹配文件名的通配符模式。 And inside the shell script you can unzip files inside the folder_path that was passed with the given wildcard pattern. 在shell脚本中,您可以解压缩使用给定通配符模式传递的folder_path中的文件。 Basically your shell execution should look like: 基本上你的shell执行应该如下所示:

sh unzip.sh <folder_path_to_monitor> <wildcard_to_files>

And use the above command in in_exec tag in your config. 并在配置中的in_exec标记中使用上述命令。 And your config will look like: 你的配置看起来像:

<source>
  @type exec
  format json
  tag unzip.sh
  command sh unzip.sh <folder_path_to_monitor> <wildcard_to_files>
  run_interval 10s
</source>

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

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