【问题标题】:Logstash not creating correct index for Filebeat and PacketbeatLogstash 没有为 Filebeat 和 Packetbeat 创建正确的索引
【发布时间】:2016-06-07 12:18:04
【问题描述】:

我已经像这样设置了我的 Elastic 堆栈。我正在尝试使用自定义索引名称通过 Filebeat 和 Topbeat 发送日志和顶级数据。

虽然,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 中创建一个索引为“custom-YYYY.MM.dd”。但它只是在 Elasticsearch 中将索引创建为“%{[@metadata][beat]}-%{+YYYY.MM.dd}”。

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

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

【问题讨论】:

    标签: elasticsearch logstash


    【解决方案1】:

    设置 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}"
        }
      }
    }
    

    当您将自定义索引与任何 Beats 一起使用时,您必须确保安装并自定义索引模板(请勿将 Logstash 的 manage_template => true 与 Beats 一起使用)。 Filebeat 在下载分发的filebeat.template.json file 中提供了它的索引模板。您需要更改template 行,使其适用于“custom-*”索引而不是“filebeat-*”。然后使用 curl -XPUT http://localhost:9200/_template/custom -d@filebeat.template.json 将模板安装到 Elasticsearch。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 2022-01-18
      • 2023-01-03
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多