Logstash conf.d 多个配置文件

概要

今天在群里一个关于在 logstash 的配置目录存在多个配置文件的时候如何处理的问题?

我的结论是加载所有配置文件并合并为一个。

 

lcy@lcy:~/ELK/logstash$ sudo /opt/logstash/bin/logstash --help
[sudo] password for lcy:
Usage:
/bin/logstash agent [OPTIONS]

Options:
-f, --config CONFIG_PATH Load the logstash config from a specific file
or directory. If a directory is given, all
files in that directory will be concatenated
in lexicographical order and then parsed as a
single config file. You can also specify
wildcards (globs) and any matched files will
be loaded in the order described above.

 

下面,做个小实验用以说明。

文件说明

1. conf.d 目录说明

存在2个配置文件 1.conf 和 2.conf

 

// 存在2个配置文件
lcy@lcy:/etc/logstash/conf.d$ ls
1.conf 2.conf

 

其中 1.conf 配置了 input ,使用 file 插件来导入文件 file_1(input中参数配置为 file_*) 的内容。并且在 fileter 中加一个 filed ,名称叫 add_from_1。输出格式为 rubydebug。

 

// 文件1.conf的内容
lcy@lcy:/etc/logstash/conf.d$ cat .conf

input {
    file {
        path => "/home/lcy/file_*"
        start_position => "beginning"
        ignore_older =>
        stat_interval =>
        discover_interval =>
    }
}
filter {
    mutate {
        add_field => {
            "add_from_1" => ""
        }
    }
}
output {
    stdout {
        codec => rubydebug
    }
}

 

其中 2.conf 没有配置 input 。在 fileter 中加一个 filed ,名称叫 add_from_2。输出格式为 JSON。

 

// 文件2.conf的内容
lcy@lcy:/etc/logstash/conf.d$ cat .conf

filter {
    mutate {
        add_field => {
            "add_from_2" => ""
        }
    }
}
output {
    stdout {
        codec => json
    }
}

 

2. 输入源文件

file_1 很简单,就一个单行 JSON 文件。

 

// file_1 的文件内容
lcy@lcy:~$ cat file_1

{"file_1":{"tag_1":"value_1"}}

 

执行结果

1. 启动 logstash

 

lcy@lcy:/etc/logstash/conf.d$ sudo /opt/logstash/bin/logstash -f /etc/logstash/conf.d/
Settings: Default pipeline workers:
Logstash startup completed

可以执行:

对配置文件进行调试 

/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d –configtest

或从命令行以交互方式运行它.它会产生很多其他信息.

/opt/logstash/bin/logstash –debug -f /etc/logstash/conf.d

或运行以下只是测试并查看已编译的配置

/opt/logstash/bin/logstash –debug –debug-config -t -f /etc/logstash/conf.d/

 

2. 输出结果

即输出了 rubydebug 格式,又输出了 JSON 格式。

 

lcy@lcy:/etc/logstash/conf.d$ sudo /opt/logstash/bin/logstash -f /etc/logstash/conf.d/
Settings: Default pipeline workers:
Logstash startup completed
{
"message" => "{\"file_1\":{\"tag_1\":\"value_1\"}}",
"@version" => "",
"@timestamp" => "2016-04-28T06:42:43.050Z",
"path" => "/home/lcy/file_1",
"host" => "lcy",
"add_from_1" => "",
"add_from_2" => ""
}
{"message":"{\"file_1\":{\"tag_1\":\"value_1\"}}","@version":"","@timestamp":"2016-04-28T06:42:43.050Z","path":"/home/lcy/file_1","host":"lcy","add_from_1":"","add_from_2":""}
^CSIGINT received. Shutting down the pipeline. {:level=>:warn}
^CSIGINT received. Terminating immediately.. {:level=>:fatal}
^CSIGINT received. Terminating immediately.. {:level=>:fatal}

 

结论

可以看出,实际执行中,把 1.conf 和 2.conf 文件的内容完全合并为了一个配置文件

INPUT :2.conf 没有配置 input 不会报错,因为 1.conf 中有(input 为必须)
FILETER :输出内容中即添加了 add_from_1 也添加了 add_from_2 两个 field
OUTPUT :输出了2种格式,rubydebug 和 JSON

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值