2016-06-07 115 views
2

我已经建立了像这样的弹性堆栈。我正在尝试通过Filebeat和Topbeat提供自定义索引名称来提供日志和顶级数据。Logstash无法为Filebeat和Packetbeat创建正确的索引

尽管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配置:

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索引为 “定制YYYY.MM.DD”。但它只是在Elasticsearch中创建索引为“%{[@metadata][beat]}-%{+YYYY.MM.dd}”。

如果我对#index: custom发表评论,它会在Elasticsearch中创建索引filebeat-YYYY.MM.dd

我错了,为什么它不适用于自定义索引模式?

回答

2

设置Filebeat output.logstash.index配置参数会导致它使用自定义索引名称覆盖[@metadata][beat]值。通常,[@metadata][beat]值是Beat的名称(例如filebeat或packetbeat)。

根据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}" 
    } 
    } 
} 

当您使用任何节拍的自定义索引,您必须确保安装和自定义索引模版(不要使用Logstash的manage_template => true与节拍)。 Filebeat在下载中分发的filebeat.template.json file中提供了其索引模板。您需要更改template行,以便它适用于“custom- *”索引而不是“filebeat- *”。然后使用curl -XPUT http://localhost:9200/_template/custom [email protected]将模板安装到Elasticsearch。