返回到文章

采纳

编辑于

Logstash的type用法

logstash
logstash
用法

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