【问题标题】:How to define seperated indexes for different logs in Filebeat/ELK?Filebeat/ELK中如何为不同的日志定义单独的索引?
【发布时间】:2016-12-14 07:33:09
【问题描述】:

我想知道如何为提取到logstash(后来被传递到elasticsearch)的不同日志创建单独的索引,以便在kibana 中为它们定义两个索引并发现它们。

就我而言,我有几个客户端服务器(每个都安装有filebeat)和一个集中式日志服务器(ELK)。每个客户端服务器都有不同类型的日志,例如redis.logpython 日志、mongodb 日志,我喜欢将它们分类到不同的索引中并存储在elasticsearch

每个客户端服务器也有不同的用途,例如数据库、用户界面、应用程序。因此我也想给它们不同的索引名称(通过更改filebeat.yml中的输出索引?)。

【问题讨论】:

    标签: elasticsearch logstash kibana elastic-stack filebeat


    【解决方案1】:

    在您的 Filebeat 配置中,您可以使用 document_type 来识别您拥有的不同日志。然后在 Logstash 内部你可以设置type 字段的值来控制目标索引。

    但是,在将日志分成不同的索引之前,您应该考虑将它们留在一个索引中,并使用type 或某些custom field 来区分日志类型。见index vs type

    Filebeat Prospector 配置示例:

    filebeat:
      prospectors:
        - paths:
            - /var/log/redis/*.log
          document_type: redis
    
        - paths:
            - /var/log/python/*.log
          document_type: python
    
        - paths:
            - /var/log/mongodb/*.log
          document_type: mongodb
    

    示例 Logstash 配置:

    input {
      beats {
        port => 5044
      }
    }
    
    output {
      # Customize elasticsearch output for Filebeat.
      if [@metadata][beat] == "filebeat" {
        elasticsearch {
          hosts => "localhost:9200"
          manage_template => false
          # Use the Filebeat document_type value for the Elasticsearch index name.
          index => "%{[@metadata][type]}-%{+YYYY.MM.dd}"
          document_type => "log"
        }
      }
    }
    

    【讨论】:

    • 您确定 filebeat 中的document_type 会在logstash 事件中创建[@metadata][type] 字段而不是[type] 字段吗?我认为它应该改为index => "%{type}-%{+YYYY.MM.dd}"
    • document_type 值用于[@metadata][type][type],因此任一字段均可用于索引。
    • document_type 在 es6+ 中不起作用,但在 es4、es5 中运行良好..我想这是我的问题..
    【解决方案2】:

    filebeat.yml

    filebeat.prospectors:
    
    - input_type: log
        paths:
        - /var/log/*.log
      fields: {log_type: toolsmessage}
    
    
    - input_type: log
      paths:
        - /etc/httpd/logs/ssl_access_*
      fields: {log_type: toolsaccess}
    

    在 logstash.conf 中。

    input {
      beats {
        port => "5043"
      }
    }
    
    filter {
      if ([fields][log_type] == "toolsmessage") {
        mutate {
          replace => {
            "[type]" => "toolsmessage"
          }
        }
      }
      else if ([fields][log_type] == "toolsaccess") {
        mutate {
          replace => {
            "[type]" => "toolsaccess"
          }
        }
      }
    }
    
    output {
      elasticsearch {
        hosts => ["10.111.119.211:9200"]
        index => "%{type}_index"
      }
     #stdout { codec => rubydebug }
    }
    

    【讨论】:

    【解决方案3】:

    在logstash中,您可以借助标签定义多个输入、过滤或输出插件:

    input {
        file {
                type => "redis"
                path => "/home/redis/log"
        }
        file {
                type => "python"
                path => "/home/python/log"
        }
    } 
    filter {
        if [type] == "redis" {
                # processing .......
        }
        if [type] == "python" {
                # processing .......
        }
    }
    output {
        if [type] == "redis" {
                # output to elasticsearch redis
                index => "redis" 
        }
        if [type] == "python" {
                # output to elasticsearch python
                index => "python"
        }
    }
    

    【讨论】:

    【解决方案4】:

    我已阅读以上所有内容。 找出我的路。

    input {
        stdin {
        }
        jdbc {
          type => "jdbc"
          ....
        }
        http_poller {
            type=>"api"
          ....
        }
    
    }
    filter {
    ....
    }
    output {
        elasticsearch {
            hosts => ["jlkjkljljkljk"]
            index => "%{type}_index"
            document_id => "%{id}"
        }
        stdout {
            codec => json_lines
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-26
      • 1970-01-01
      • 2019-12-16
      • 2019-08-25
      • 1970-01-01
      • 2023-02-03
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多