设置高级的Logstash 管道

来源:互联网 发布:怎么找网络水军公司 编辑:程序博客网 时间:2024/05/21 19:24
设置高级的Logstash 管道:一个Logstash 管道在很多实用例子有一个或者多个输入,filter,和output 插件。本节中 创建Logstash 配置文件来指定那些插件和讨论每个插件做什么Logstash 配置文件定义你的Logstash 管道。当你开始一个Logstash 例子,实用 -f <path/to/file> 选项来指定配置文件,定义实例的管道。一个Logstash 管道有2个需要的元素, 输入和输出,和一个可选的元素,filter.input 插件吸收源数据,filter 插件修改你指定的数据,ouput 插件写数据到一个目的地下面的文本表示配置管道的骨架:# The # character at the beginning of a line indicates a comment. Use# comments to describe your configuration.input {}# The filter part of this file is commented out to indicate that it is# optional.# filter {## }output {}filter 部分是注释掉的表明它是可选的这个骨架是非功能的,因为输入 和输出章节没有任何有效的定义。在本教程中的例子创建配置文件来解决特定的使用案例。解析 Apache Logs 到Elasticsearch:这个例子 创建一个Logstash 管道让Apache web logs 作为输入, 解析那些logs 来创建特定的,命令的字段从logs,写解析的数据到一个Elasticsearch cluster.你可以下载相同的数据集用于这个例子,解压文件:配置Logstash 用于文件输入:开始你的Logstash 管道, 配置Logstash 实例从一个使用文件输入的插件读取数据Edit the first-pipeline.conf file to add the following text:input {    file {        path => "/path/to/logstash-tutorial.log"        start_position => beginning         ignore_older => 0     }}默认文件的行为input 插件来监控一个文件对于新的信息, 方式类似于UNIX tail -f 命令。改变这个默认的行为和处理整个文件, 我们需要指定位置 Logstash 开始处理文件的位置默认的文件输入插件的行为是忽视文件最后修改是大于86400s,来改变这个默认行为和处理文件(一天前的文件),我们需要指定忽略的日期解析 Web Logs 使用Grok Filter 插件:grok filter 插件是 其中的一种插件默认在Logstash里是可用的,对于细节如何管理Logstash 插件,查看插件管理器的文档内容。因为grok 过滤插件寻找模式在进来的日志数据,配置需要你做出如何确定模式 。从Web服务器典型的行看起来像这样:83.149.9.216 - - [04/Jan/2015:05:13:42 +0000] "GET /presentations/logstash-monitorama-2013/images/kibana-search.pngHTTP/1.1" 200 203023 "http://semicomplete.com/presentations/logstash-monitorama-2013/" "Mozilla/5.0 (Macintosh; IntelMac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"在开始行的IP地址 是很容易识别, 在括号中的时间戳,在这种情况下,使用 %{COMBINEDAPACHELOG} grok 模式,Apache log 使用下面的模式 :InformationField NameIP AddressclientipUser IDidentUser AuthenticationauthtimestamptimestampHTTP VerbverbRequest bodyrequestHTTP VersionhttpversionHTTP Status CoderesponseBytes servedbytesReferrer URLreferrerUser agentagentfilter {    grok {        match => { "message" => "%{COMBINEDAPACHELOG}"}    }}在处理后,简单的行有下面的JSON 输出:{"clientip" : "83.149.9.216","ident" : ,"auth" : ,"timestamp" : "04/Jan/2015:05:13:42 +0000","verb" : "GET","request" : "/presentations/logstash-monitorama-2013/images/kibana-search.png","httpversion" : "HTTP/1.1","response" : "200","bytes" : "203023","referrer" : "http://semicomplete.com/presentations/logstash-monitorama-2013/","agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"}Indexing Parsed 数据到elasticsearch:现在web日志 是被分解成多个特定的字段,Logstash 管道可以索引数据到一个Elasticsearch cluster.output {    elasticsearch {    }}在这个配置里,Logstash 使用http 协议来连接Elasticsearch。 上面的例子假设Logstash和Elasticsearch  运行在相同的实例。你可以指定一个远程的实例使用主机配置像 hosts => "es-machine:9092".加强你的数据使用 Geoip 过滤插件除了解析log data 一伙的更好的搜索,filter 插件可以得到补充的信息从存在的数据。比如一个例子,geoip 插件查找ip地址,获得地理位置信息从地址,增加位置信息到logs.配置你的Logstash 实例 使用geoip 过滤插件通过增加下面的行到你的filter 章节:geoip {    source => "clientip"} geoip plugin 配置需要数据是已经定义作为单独的字段,确保geoip 章节是在grok章节后面指定字段的名字 包含IP地址来查询,在这里,字段名是clientip测试你的初始化管道:在这一点上,你的first-pipeline.conf 有input,filter,和output 章节合适的配置,看起来像这样;input {    file {        path => "/Users/palecur/logstash-1.5.2/logstash-tutorial-dataset"        start_position => beginning    }}filter {    grok {        match => { "message" => "%{COMBINEDAPACHELOG}"}    }    geoip {        source => "clientip"    }}output {    elasticsearch {}    stdout {}}校验你的配置,使用下面的命令:bin/logstash -f first-pipeline.conf --configtest多个输入和输出插件;信息你需要管理经常来自多个不同的源,使用例子可以需要多个目的地对于你的数据。你的Logstash  管道可以使用多个input 和output 插件来处理那些需求:这个例子创建一个Logstash 管道 输入从一个 Twitter feed 和 Filebeat client, 然后发送信息到 Elasticsearch cluster 也写信息到文件

0 0
原创粉丝点击