Logstash的type用法

半兽人 发表于: 2016-12-08   最后更新时间: 2022-02-14 13:01:37  
{{totalSubscript}} 订阅, 7,531 游览

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"}

更新于 2022-02-14
在线,27分钟前登录

查看logstash更多相关的文章或提一个关于logstash的问题,也可以与我们一起分享文章