如果日志包含特定字段,如何限制 Filebeat 仅将日志发送到 ELK?
How to constrain Filebeat to only ship logs to ELK if they contain a specific field?
我正在尝试使用 Filebeat 从 Kubernetes 节点收集日志,如果日志来自特定的 Kubernetes 命名空间,则仅将它们发送到 ELK。
到目前为止,我发现您可以定义 Processors,我认为它可以实现这一点。但是,无论我做什么,我都无法约束已发送的日志。这样看起来对吗?
嗯,这样看起来正确吗?
filebeat.config:
inputs:
path: ${path.config}/inputs.d/*.yml
reload.enabled: true
reload.period: 10s
when.contains:
kubernetes.namespace: "NAMESPACE"
modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
processors:
- add_kubernetes_metadata:
namespace: "NAMESPACE"
xpack.monitoring.enabled: true
output.elasticsearch:
hosts: ['elasticsearch:9200']
尽管有这种配置,我仍然从所有命名空间获取日志。
Filebeat 运行 作为 Kubernetes 上的 DaemonSet。以下是扩展日志条目的示例:https://i.imgur.com/xfTwbhl.png
您有多种选择:
processors:
- drop_event:
when:
contains:
source: "field"
output.elasticsearch:
hosts: ["localhost:9200"]
pipeline: my_pipeline_id
然后测试事件变成pipeline:
{
"drop": {
"if" : "ctx['field'] == null "
}
}
filter {
if ![field] {
drop { }
}
}
最后,我通过将放置处理器从配置文件移动到输入配置文件来解决这个问题。
我正在尝试使用 Filebeat 从 Kubernetes 节点收集日志,如果日志来自特定的 Kubernetes 命名空间,则仅将它们发送到 ELK。
到目前为止,我发现您可以定义 Processors,我认为它可以实现这一点。但是,无论我做什么,我都无法约束已发送的日志。这样看起来对吗?
嗯,这样看起来正确吗?
filebeat.config:
inputs:
path: ${path.config}/inputs.d/*.yml
reload.enabled: true
reload.period: 10s
when.contains:
kubernetes.namespace: "NAMESPACE"
modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
processors:
- add_kubernetes_metadata:
namespace: "NAMESPACE"
xpack.monitoring.enabled: true
output.elasticsearch:
hosts: ['elasticsearch:9200']
尽管有这种配置,我仍然从所有命名空间获取日志。
Filebeat 运行 作为 Kubernetes 上的 DaemonSet。以下是扩展日志条目的示例:https://i.imgur.com/xfTwbhl.png
您有多种选择:
processors:
- drop_event:
when:
contains:
source: "field"
output.elasticsearch:
hosts: ["localhost:9200"]
pipeline: my_pipeline_id
然后测试事件变成pipeline:
{
"drop": {
"if" : "ctx['field'] == null "
}
}
filter {
if ![field] {
drop { }
}
}
最后,我通过将放置处理器从配置文件移动到输入配置文件来解决这个问题。