概要

今天在群里一个关于在 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
.conf .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

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 两个 filed
OUTPUT :输出了2中格式,rubydebug 和 JSON

Logstash conf.d 多个配置文件的更多相关文章

  1. ELK学习笔记之Logstash不停机自动重载配置文件

    0x00 自动重新加载配置 为了可以自动检测配置文件的变动和自动重新加载配置文件,需要在启动的时候使用以下命令: ./bin/lagstash -f configfile.conf --config. ...

  2. logstash/conf.d文件编写

    logstash-01.conf input { beats { port => 5044 host => "0.0.0.0" type => "log ...

  3. smb.conf - Samba组件的配置文件

    总览 SYNOPSIS smb.conf是Samba组件的配置文件,包含Samba程序运行时的配置信息.smb.conf被设计成可由swat (8)程序来配置和管理.本文件包含了关于smb.conf的 ...

  4. svnserve.conf - snvserve 的仓库配置文件

    SYNOPSIS 总览 repository-path/conf/svnserve.conf DESCRIPTION 描述 每个代码仓库都有一个 svnserve.conf 文件来控制 svnserv ...

  5. nginx.conf nginx反向代理配置文件

    nginx反向代理配置文件 nginx.conf proxy_default.conf proxy.conf vhost/*.conf upstream/*.conf cache/*.conf ngi ...

  6. nginx.conf 文中描述的配置文件

    ###############################nginx.conf 件里文说明 #user nobody; # user 主模块指令,指令nginx worker 执行用户和用户组(u ...

  7. /etc/sysctl.conf 控制内核相关配置文件

    /etc/sysctl.conf 用于控制内核相关的配置参数,而且它的内容全部是对应于 /proc/sys/ 这个目录的子目录及文件 [root@MongoDB ~]# ll /proc/sys to ...

  8. logstash.conf 根据不同地址创建索引

    input { http { host => "0.0.0.0" port => 9700 type => "from_ys" }}input ...

  9. centos7搭建ELK Cluster集群日志分析平台(二):Logstash

    续  centos7搭建ELK Cluster集群日志分析平台(一) 已经安装完Elasticsearch 5.4 集群. 安装Logstash步骤 . 安装Java 8 官方说明:需要安装Java ...

随机推荐

  1. Web网站常规测试方法

    功能测试 1. 安装测试: 安装过程中对于缺省安装目录及任意指定的安装目录,是否都能正确安装: 若是选择安装,查看能否实现其相应的功能: 在所有能中途退出安装的位置退出安装程序后,验证此程序并未安装成 ...

  2. C语言断言

    1.概述 断言是对某种假设条件进行检查(可理解为若条件成立则无动作,否则应报告),它可以快速发现并定位软件问题,同时对系统错误进行自动报警.断言可以对在系统中隐藏很深,用其它手段极难发现的问题进行定位 ...

  3. 使用X-UA-Compatible来设置IE兼容模式

    转自:http://www.cnblogs.com/libra/archive/2009/03/24/1420731.html 英文原文:http://msdn.microsoft.com/en-us ...

  4. powerdesign的license key到期,解决办法

    到2013年9月24日为止我把这文件覆盖了都是行的!不行的请留言说明下! 下载地址:powerdesigner license key 15.1 找到安装目录,直接覆盖就行了!

  5. php 仿百度文库

    http://www.haosblog.com/?mod=article_read&id=386

  6. Linq to Sql 总生成 where ID is null 的解决办法

    using (Entities com = new Entities()){     com.Configuration.UseDatabaseNullSemantics = true; } EF+M ...

  7. Android Studio 模拟器启动问题——黑屏 死机 解决方法

    今天用了下Android Studio,出现了一些问题,现在将启动过程中遇到的问题和解决方案列出来,方便大家参考. 安装过程不多说,网上一搜一大把. 那直接说问题吧: 1. 无法启动,报错:Faile ...

  8. IAR 编译错解决Error[e16]: Segment NEAR_Z (size: 0x16d align: 0) is too long for segment definition. At least 0x83 more bytes needed.

    Error[e16]: Segment NEAR_Z (size: 0x16d align: 0) is too long for segment definition. At least 0x83 ...

  9. 关于Windows文件名和路径名的那些事

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:关于Windows文件名和路径名的那些事.

  10. Rank of Tetris(hdu1811拓扑排序+并查集)

    题意:关于Rating的信息.这些信息可能有三种情况,分别是"A > B","A = B","A < B",分别表示A的Rati ...