6

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

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

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

4

4 回答 4

7

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

但是,在将日志分成不同的索引之前,您应该考虑将它们留在单个索引中,并使用其中一个type或一些自定义字段来区分日志类型。请参阅索引与类型

示例 Filebeat 探矿者配置:

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"
    }
  }
}
于 2016-08-08T21:58:18.690 回答
2

文件节拍.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 }
}
于 2019-01-04T06:28:16.547 回答
1

在 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"
    }
}
于 2016-08-08T18:57:12.737 回答
0

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

input {
    stdin {
    }
    jdbc {
      type => "jdbc"
      ....
    }
    http_poller {
        type=>"api"
      ....
    }

}
filter {
....
}
output {
    elasticsearch {
        hosts => ["jlkjkljljkljk"]
        index => "%{type}_index"
        document_id => "%{id}"
    }
    stdout {
        codec => json_lines
    }
}
于 2019-07-09T03:23:27.643 回答