我试图用logstash做一个简单的任务:我需要在日志文件上计算loglevel。我尝试使用指标过滤器。
为了进行测试,我使用了一个简单的文件:
INFO
WARN
INFO
WARN
INFO
WARN
INFO
我使用这个conf文件:
input {
stdin { type => "api" }
}
filter {
grok {
match => [ "message", "%{LOGLEVEL:loglevel}" ]
}
if [loglevel] == "WARN" {
metrics {
meter => "warn"
add_tag => "metric"
}
}
}
output {
if "metric" in [tags] {
stdout {
codec => line {
format => "warn count: %{[warn][count]}"
}
}
}
}
警告计数是准确的,我得到这个输出:
io/console not supported; tty will not be manipulated
Settings: Default pipeline workers: 8
Logstash startup completed
warn count: 3
warn count: 3
warn count: 3
warn count: 3
warn count: 3
warn count: 3
warn count: 3
warn count: 3
warn count: 3
Logstash shutdown completed
任何人都可以解释为什么我总是有9行输出?我怎么能只获得一条线?
答案 0 :(得分:0)