簡體   English   中英

Logstash配置條件

[英]Logstash configuration condition

我是Logstash的新成員,elasticsearch。

我有NodeJS應用,我通過Winston:Redis發送日志。 我有不同類型的日志,例如請求,系統等。我希望這些日志在ElasticSearch中位於單獨的index_type中。

我正在發送這些密鑰。 :“ web:production:request”,“ web:production:system”並即時發送JSON對象。

我的配置是:

NodeJS(Winston Redis客戶端)-> Redis-> Logstash->彈性搜索

除了index_types之外,它的工作情況都很好。

我有1個Redis客戶端(流/訂閱),我想根據彈性搜索輸出內不同index_type的鍵值來過濾這些日志。

我嘗試了這個配置:

input {
    redis {
        host => "127.0.0.1"
        data_type => "pattern_channel"
        key => "web:production:*"
        codec => json
    }

filter {
    if [key] == "web:production:request" {
        alter {
            add_field => { "index_type" => "request" }
        }
    }

    if [key] == "web:production:system" {
        alter {
            add_field => { "index_type" => "system" }
        }
    }
}

output {
    elasticsearch {
        index => "web-production-%{+YYYY.MM.dd}"
        index_type => "%{index_type}"
        # THIS IS NOT WORKING
        protocol => "http"
    }
}

所以問題是:

  1. 有條件的條件如何?

  2. 如果要根據條件發送不同的索引,該如何處理

  3. 我命令中沒有條件嗎? fe。 grok {如果[key] ==“ 1” {}}?

解決方法的建議:

output {
  if [index_type] == "request"{
    elasticsearch {
      index => "web-production-request%{+YYYY.MM.dd}"
      protocol => "http"
    }
  }
  if [index_type] == "system"{
    elasticsearch {
      index => "web-production-system%{+YYYY.MM.dd}"
      protocol => "http"
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM