logstash的type用法

半兽人 发表于: 2016-12-08   最后更新时间: 2016-12-08  
  •   0 订阅,85 游览

logstash的type用法灵活,直接上代码即可。

input {
        file {  
                type => "type_a"  
                path => ["/usr/local/logstash-2.3.4/config/type/a.txt"]  
        }  

       file {   
                type => "type_b"   
                path => ["/usr/local/logstash-2.3.4/config/type/b.txt"]   
        }
}

output {  
     if [type] == "type_a" {   
        redis {  
                host => "127.0.0.1"  
                data_type => "list"  
                key => "type_a:redis"  
                port=>"6379"  
                password => "1234567"  
        }  
      }  
      else if [type] == "type_b"{  
       redis {   
                host => "127.0.0.1"   
                data_type => "list"   
                key => "type_b:redis"   
                port=>"6379"   
                password => "1234567"   
        }   
}  
}

再来

input {  

        redis {  
                host => "127.0.0.1"  
                data_type => "list"  
                key => "type_a:redis"  
                password => "1234567"  
                port =>"6379"  
        }  


        redis {  
                host => "127.0.0.1"  
                data_type => "list"  
                key => "type_b:redis"  
                password => "1234567"  
                port =>"6379"  
        }  


}  
output {  
      if   [type] == "type_a"{   
        stdout {  
            codec => rubydebug  
        }  
      }    
      else if  [type] == "type_b"{  
                stdout {  
                        codec =>json  
                }   
  }  

}

执行

./bin/logstash -f config/output.conf
Settings: Default pipeline workers: 1  
Pipeline main started  
{  
       "message" => "aaaaaaaa",  
      "@version" => "1",  
    "@timestamp" => "2016-09-16T06:26:07.211Z",  
          "path" => "/usr/local/logstash-2.3.4/config/type/a.txt",  
          "host" => "0.0.0.0",  
          "type" => "type_a"  
}  


{"message":"aaaaaaaa","@version":"1","@timestamp":"2016-09-16T06:26:31.079Z","path":"/usr/local/logstash-2.3.4/config/type/b.txt","host":"0.0.0.0","type":"type_b"}






发表于: 1月前   最后更新时间: 1月前   游览量:85
上一条: logstash区分不同数据源并输出到不同的地方
下一条: liunx下elasticSearch 5.1.1安装及head安装
评论…

  • 评论…
    • in this conversation
      提问