我正在嘗試洗掉 200 個代碼的日志以回應 Prometheus 抓取。在 Kibana 中,這是訊息欄位:
November 17th 2021, 12:37:01.769 10.128.8.31 - - [17/Nov/2021:12:37:01 0000] "GET /metrics HTTP/1.1" 200 36881 "-" "Prometheus/2.25.0"
我在 logstash 配置中的過濾器中添加了以下內容:
if [message] =~ /.*Prometheus\/2.25.0$/ {
drop { }
}
但是日志仍在通過,我嘗試了很多變體,但似乎沒有任何效果,所以我不確定我錯過了什么?
謝謝
uj5u.com熱心網友回復:
由于您正在攝取 Apache 日志,您可以嘗試使用預定義grok模式決議該行,然后根據用戶代理簡單地洗掉事件。
使用COMBINEDAPACHELOG模式查看您共享的 Apache 日志(可以在此處找到更多模式)將決議該message欄位,如下所示:
{
"clientip": [
[
"10.128.8.31"
]
],
"ident": [
[
"-"
]
],
"auth": [
[
"-"
]
],
"timestamp": [
[
"17/Nov/2021:12:37:01 0000"
]
],
"verb": [
[
"GET"
]
],
"request": [
[
"/metrics"
]
],
"httpversion": [
[
"1.1"
]
],
"rawrequest": [
[
null
]
],
"response": [
[
"200"
]
],
"bytes": [
[
"36881"
]
],
"referrer": [
[
""-""
]
],
"agent": [
[
""Prometheus/2.25.0""
]
]
}
所以現在你要做的就是drop根據agent欄位的值來處理事件:
filter {
# first grok the Apache log
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
# then drop if you want to ignore a given user-agent
if [agent] == "Prometheus\/2.25.0" {
drop {}
}
}
uj5u.com熱心網友回復:
將檢查放入 if 陳述句中,我正在檢查 kubernetes 命名空間的作業,即
if "example-namespace" in [kubernetes][namespace] {
mutate { add_field => { "proj_index" => "example-namespace"} } json {
source => "message"
}
if [message] =~ /.*Prometheus\/2.25.0"$/ {
drop { }
}
}
}
將 drop 條件放在過濾器內但在任何特定命名空間之外是行不通的,因此出于某種原因它會應用于所有這些。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/365808.html
上一篇:多個值的彈性搜索順序
