Logstash 配置(一)input配置
標准輸入(Stdin)
我們已經見過好幾個示例使用 stdin 了。這也應該是 logstash 里最簡單和基礎的插件了。
[root@bigdata111 confs_test]# vi input_stdin.conf
input {
stdin {
add_field => {"key" => "value"}
codec => "plain"
tags => ["add"]
type => "std"
}
}
output{stdout{codec=>rubydebug}}
注:add_field要添加字段的名稱-這里叫做key
tags:又加了的字段
type這里換成了’std’(這是可以自己隨便設的)
----------------------------------------------------------------
我建議大家把整段配置都寫入一個文本文件,
然后運行命令:../bin/logstash -f ./input_stdin.conf。
[root@bigdata111 confs_test]# ../bin/logstash -f ./input_stdin.conf
因為是標准的輸入,所以啟動LS之后就直接在控制台輸入即可,輸出也是在當前控制台。
輸入 "hello world" 並回車后,你會在終端看到如下輸出:
解釋
type 和 tags 是 logstash 事件中兩個特殊的字段。
通常來說我們會在輸入區段中通過 type 來標記事件類型。
而 tags 則是在數據處理過程中,由具體的插件來添加或者刪除的。
最常見的用法是像下面這樣:
input {
stdin {
type => "web"
}
}
filter {
if [type] == "web" {
grok {
match => ["message", %{COMBINEDAPACHELOG}]
}
}
}
output {
if "_grokparsefailure" in [tags] {
nagios_nsca {
nagios_status => "1"
}
} else {
elasticsearch {
}
}
}