我像这样设置了我的弹性堆栈。我试图通过Filebeat和Topbeat使用自定义索引名发送日志和top数据。
尽管如此,Logstash并没有为我通过自定义索引名传递的数据创建任何索引。
Logstash配置:
input{
beats{
port => 27080
congestion_threshold => 1500
}
jmx {
path => "file://Machine01/Users/username/projects/Logstash/logstash/bin/jmx"
polling_frequency => 15
type => "jmx"
nb_thread => 4
}
}
filter {
if [type] == "Type1"{
grok{
break_on_match => false
patterns_dir => ["C:\Users\users\projects\Logstash\logstash\bin\patterns"]
match => { "message" => "%{YEAR:Year}%{MONTHNUM:Month}%{MONTHDAY:Day} %{HOUR:Hour}%{MINUTE:Minute}%{SECOND:Second} %{LogLevel:LogVerbosity} %{MODULE:MODULENAME}%{SPACE}%{MESSAGEID:MESSAGEID} %{SUBMODULE:SUBMODULE} %{MESSAGE:MESSAGE}"}
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
add_tag => ["Groked"]
}
if "_grokparsefailure" in [tags] {
drop { }
}
if [type] == "jmx" {
if ("OperatingSystem.ProcessCpuLoad" in [metric_path] or "OperatingSystem.SystemCpuLoad" in [metric_path]) {
ruby {
code => "event['cpuLoad'] = event['metric_value_number'] * 100"
add_tag => [ "cpuLoad" ]
}
}
}
}
}
output {
if [type] == "jmx" {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "jmx-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
hosts => ["http://localhost:9200"]
manage_template => true
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
if [type] == "dbtable" {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "dbtable-%{+YYYY.MM.dd}"
}
}
}
}
文件节拍配置:
filebeat:
prospectors:
- paths:
- test.log
input_type: log
tail_files: false
scan_frequency: 3s
backoff: 20s
backoff_factor: 1
document_type: custom
registry:
fields:
type: custom
spool_size: 10000
idle_timeout: 2s
output:
logstash:
index: custom
hosts: ["valid hostname"]
logging:
to_files: true
files:
path: ./
name: filebeat.log
rotateeverybytes: 10485760
level: debug
我期望当我设置index: custom
时,它应该在Elasticsearch中创建一个索引为"custom-YYYY.MM.dd“。但它只是在Elasticsearch中将索引创建为"%{[@metadata][beat]}-%{+YYYY.MM.dd}
“。
如果我注释#index: custom
,它将在Elasticsearch中以filebeat-YYYY.MM.dd
的形式创建索引。
在我错的地方,为什么它不能用于自定义索引模式?
发布于 2016-08-10 02:21:59
设置Filebeat output.logstash.index
配置参数会导致它用自定义索引名称覆盖[@metadata][beat]
值。通常,[@metadata][beat]
值是节拍的名称(例如文件节拍或数据包节拍)。
根据Logstash测试您的Filebeat配置,结果显示[@metadata][beat]
的值确实被设置为custom
,因此您的Filebeat配置工作正常。
输出配置中使用的条件逻辑可能存在问题。我简化了您的输出配置,使其更简洁。
output {
# Remove this after you finish debugging.
stdout { codec => rubydebug { metadata => true } }
if [@metadata][beat] {
# Use this output only for Beats.
elasticsearch {
hosts => ["http://localhost:9200"]
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
} else if [type] == "jmx" or [type] == "dbtable" {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[type]}-%{+YYYY.MM.dd}"
}
}
}
当您对任何Beat使用自定义索引时,必须确保安装和自定义索引模板(不要将Logstash的manage_template => true
与Beat一起使用)。Filebeat在下载中分发的filebeat.template.json
file中提供了它的索引模板。您需要更改自定义行,使其应用于“template
-*”索引,而不是"filebeat-*“。然后使用curl -XPUT http://localhost:9200/_template/custom -d@filebeat.template.json
将模板安装到Elasticsearch。
https://stackoverflow.com/questions/37679179
复制相似问题