2016-06-07 98 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。