logstash - 将输入标识符添加到 docker 中的 logstash 日志记录
问题描述
我的 logstash 管道中有一个带有多个 URL 和一个到 elasticsearch 的输出的 http_poller 插件。我还有一个自定义 log4j2.properties 文件(其中还没有自定义)。我遇到的问题是,当 output.elasticsearch 失败时,日志记录没有给我足够的上下文来说明哪个输入 url 是原因。所以有几个问题:
- 如何将对象中的字段添加到日志记录中?我见过使用
%notEmpty{[%X{pipeline.id}]}
但不知道如何使用管道中文档中的字段。 - 如何在 http_poller 插件中为每个 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}"}}}}
解决方案
通常它应该使用您已有的配置在输出事件中打印“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
推荐阅读
- crystal-lang - 有没有办法使用“本机”Crystal 来确定它是否在交互式 shell 会话中运行?
- javascript - How does this snippet in Chapter 7 of Eloquent Javascript work?
- java - Java - ArrayList 仅从数据库返回一个值
- css - Bootstrap 3.3.7 更改导航栏中折叠堆栈的悬停/活动颜色?
- paypal - 动态自定义值贝宝按钮
- neo4j - Neo4j:仅从可能的子路径返回根节点
- android - 新活动调用 OnCreate 时崩溃
- database - 为什么在 Heroku 应用程序中我的数据库没有从 Heroku ClearDB 加载?
- java - 为什么空赋值前的引用值返回给调用方法?
- javascript - 打破 Array 循环函数的循环(map、forEach 等)