我的配置:
input {
tcp {
port => 5544
codec => json_lines
}
}
output{
file {
path => "/tmp/%{source_host}"
}
}
使用您的示例日志输出到文件 /tmp/foo。
echo '{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z", "source_host":"foo","message":"testmsg"}' | nc localhost 5544
编辑:这是我的测试结果:
pancake$ echo '{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z", "source_host":"foo","message":"testmsg"}' | nc localhost 5544
pancake$ cat /tmp/foo
{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z","source_host":"foo","message":"testmsg","port":56716}
pancake$ echo '{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z", "source_host":"bar","message":"testmsg"}' | nc localhost 5544
pancake$ echo '{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z", "source_host":"bar","message":"one more message!"}' | nc localhost 5544
pancake$ cat /tmp/bar
{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z","source_host":"bar","message":"testmsg","port":56717}
{"version":"debug","host":"devel","level":5,"@version":"1","@timestamp":"2016-09-15T10:41:00.549Z","source_host":"bar","message":"one more message!","port":56718}
编辑2:哦,我只是想到了一些事情。您之前说过您没有使用任何过滤器,对吧?您需要使用某种过滤器,否则该字段source_host
将不存在。如果您codec => json_lines
的输入块中有(因为您的日志是 JSON),就像我在我的示例中所做的那样,它会将您的 JSON 解析为键值对。如果您没有过滤器或编解码器,则整个日志正文将存储在message
字段中,未经修改。尝试添加输入编解码器,看看是否有帮助。