首页 > 解决方案 > 将输入标识符添加到 docker 中的 logstash 日志记录

问题描述

我的 logstash 管道中有一个带有多个 URL 和一个到 elasticsearch 的输出的 http_poller 插件。我还有一个自定义 log4j2.properties 文件(其中还没有自定义)。我遇到的问题是,当 output.elasticsearch 失败时,日志记录没有给我足够的上下文来说明哪个输入 url 是原因。所以有几个问题:

input {
    http_poller {
        id => "medium-pull"
        urls => {
            url1 => {               
                method => post
                url => "${ROOT}/endpoint1"
                body => '{"ids": [],  "limit": 10000,  "page": 1}'
            }

            url2 => {               
                method => post
                url => "${ROOT}/endpoint2"
                body => '{"ids": [],  "limit": 10000,  "page": 1}'
            }

错误日志示例:

logstash-pull1   | [2021-07-22T14:11:35,112][WARN ][logstash.outputs.elasticsearch][main][elasticsearch]  
Could not index event to Elasticsearch. 
{:status=>404, :action=>["index", {:_id=>"%{id}", :_index=>"prefix-%{objectType}", :routing=>nil, :_type=>"_doc"}, 
#<LogStash::Event:0x77f611be>], :response=>{"index"=>{"_index"=>"prefix-%{objectType}", "_type"=>"_doc", "_id"=>"%{id}", "status"=>404, "error"=>{"type"=>"index_not_found_exception", "reason"=>"no such index [prefix-%{objectType}] and [action.auto_create_index] ([\".security*,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*\"]) doesn't match", "index_uuid"=>"_na_", "index"=>"prefix-%{objectType}"}}}}

标签: logstashlog4j2

解决方案


通常它应该使用您已有的配置在输出事件中打印“name”=>“url”。这样,您应该能够确定哪些url有问题等。

另一种方法是有两个http_pollers不同id的 s 例如

input {
    http_poller {
        id => "medium-pull"
        urls => {
            url1 => {               
                method => post
                url => "${ROOT}/endpoint1"
                body => '{"ids": [],  "limit": 10000,  "page": 1}'
            }
          }
        }

    http_poller {
       id => "large_pull"
       urls => {
            url2 => {               
                method => post
                url => "${ROOT}/endpoint2"
                body => '{"ids": [],  "limit": 10000,  "page": 1}'
            }
         }
      }

    }

我相信你可能已经看过这个文档,但以防万一你没有https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http_poller.html


推荐阅读