我有一个运行java应用程序,它将其日志发送到logstash,它基于本教程http://www.andrew-programming.com/2018/09/18/integrate-springboot-application-with-elk-and-filebeat/
我的问题是,如果我想将我的日志与不同的应用程序分开,我想为每个应用程序使用不同的索引模式,而不是将它们全部放在同一个应用程序中。
这是我的logstash配置文件,其中index =>“app - %{+ YYYY.MM.dd}”是模式的名称。
我已经尝试了类似%{type}%{tags} [tags] [type]的内容,但没有一个打印任何与应用程序相关的变量。我可以在索引模式中使用主机但不希望使用ip地址因为它们可能会发生变化。
input {
tcp {
port => 4560
codec => json_lines
}
beats {
host => "127.0.0.1"
port => "5044"
}
}
output{
stdout { codec => rubydebug }
elasticsearch {
hosts => ["localhost:9200"]
index => "app-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
将以下内容添加到logback.spring.xml中
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"appname":"auxiliary-service-application"}</customFields>
</encoder>
在logstash.conf文件中使用了该参数。
output{
stdout { codec => rubydebug }
elasticsearch {
hosts => ["localhost:9200"]
index => "%{appname}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
我认为这会有所帮助
例如:
input {
file {
path => "C:/_Logs/*.log"
start_position => "beginning"
add_field => {
"log_origin" => "XYZ"
}
}
file {
path => "C:/_Data/*.csv"
start_position => "beginning"
add_field => {
"log_origin" => "ABC"
}
}
output {
if ( "XYZ" in [log_origin] ) {
elasticsearch {
hosts => "10.0.0.0:9200"
index => "deploy-%{+yyyy.MM.dd}"
}
}
else {
elasticsearch {
hosts => "10.0.0.0:9200"
index => "validator-%{+yyyy.MM.dd}"
}
}
}