【问题标题】:Logstash multiple logsLogstash 多条日志
【发布时间】:2017-07-24 16:59:46
【问题描述】:

我正在关注一个在线教程,并获得了一个 cars.csv 文件和以下 Logstash 配置文件。我的 logstash 运行良好,并且在我们说话时正在为 CSV 编制索引。

问题是,我有另一个日志文件(完全不同的数据),我需要对其进行解析并索引到不同的索引中。

  1. 如何在不重新启动 logstash 的情况下添加此配置?
  2. 如果上述方法不可行,我编辑配置文件,然后重新启动 logstash - 它不会重新索引整个汽车文件吗?
  3. 如果我这样做 2. 如何为多种样式的日志文件格式化配置。

例如。我的新日志文件如下所示:

01-01-2017 ORDER FAILED: £12.11 Somewhere : Fraud

现有配置文件:

    input {
    file {
           path => "/opt/cars.csv"
           start_position => "beginning" 
           sincedb_path => "/dev/null"
         }
     }

    filter {
       csv {
          separator => ","
          columns =>
          [
                "maker",
                "model",
                    "mileage",
                        "manufacture_year",
                            "engine_displacement",
                            "engine_power",
                            "body_type",
                    "color_slug",
                "stk_year",
            "transmission",
                    "door_count",
            "seat_count",
            "fuel_type",
            "date_last_seen",
            "date_created",
            "price_eur"
         ]
    }

    mutate {
       convert => ["mileage", "integer"]
    }
    mutate {
       convert => ["price_eur", "float"]
    }
    mutate {
           convert => ["engine_power", "integer"]
    }
    mutate {
      convert => ["door_count", "integer"]
    }
    mutate {
           convert => ["seat_count", "integer"]
    }
    }

     output {
      elasticsearch {
       hosts => "localhost"

       index => "cars"
       document_type => "sold_cars"
     }

     stdout {}
    }

orders.log 的配置文件

    input {
      file {
            path => "/opt/logs/orders.log"
            start_position => "beginning"
            sincedb_path => "/dev/null"
        }
    }

   filter {
       grok {
          match => { "message" => "(?<date>[0-9-]+) (?<order_status>ORDER [a-zA-Z]+): (?<order_amount>£[0-9.]+) (?<order_location>[a-zA-Z]+)( : (?<order_failure_reason>[A-Za-z ]+))?"}
          }

         mutate {
              convert => ["order_amount", "float"]
            }
          }

       output {
       elasticsearch {
               hosts => "localhost"

               index => "sales"
               document_type => "order"
     }

    stdout {}
     }

免责声明:我是一个完全的新手。使用 ELK 的第二天。

【问题讨论】:

    标签: elasticsearch logstash logstash-configuration


    【解决方案1】:

    对于第 1 点,您可以在 logstash.yml 文件中设置

    config.reload.automatic:true

    或者,在使用 conf 文件执行 logstash 时,像这样运行它:

    bin/logstash -f conf-file-name.conf --config.reload.automatic
    

    完成这些设置后,您可以启动您的 logstash,从现在开始,您在 conf 文件中所做的任何更改都将得到反映。

    【讨论】:

      【解决方案2】:

      2. If above isn't possible and I edit the config file then restart logstash - it won't reindex the entire cars file will it?

      如果您使用sincedb_path =&gt; "/dev/null",Logstash 不会记住停止读取文档的位置,并且会在每次重新启动时重新索引它。如果您希望 Logstash 记住,则必须删除此行(请参阅 here)。

      3.How do I format the config for multiple styles of log file.

      要支持多种样式的日志文件,您可以在文件输入上放置标签(请参阅https://www.elastic.co/guide/en/logstash/5.5/plugins-inputs-file.html#plugins-inputs-file-tags),然后在文件配置中使用条件(请参阅https://www.elastic.co/guide/en/logstash/5.5/event-dependent-configuration.html#conditionals)。

      像这样:

      file {
          path => "/opt/cars.csv"
          start_position => "beginning" 
          sincedb_path => "/dev/null"
          tags => [ "csv" ]
      }
      
      
      file {
          path => "/opt/logs/orders.log"
          start_position => "beginning"
          sincedb_path => "/dev/null"
          tags => [] "log" ]
      }
      
      
      if csv in [tags] {
          ...
      } else if log in [tags] {
          ...
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多