典型报错:
Expected one of #, {, ,, ] at line X, column Y常见错误:
✅ 正确示例:
grok {
match => { "message" => "%{COMMONAPACHELOG}" }
}❌ 错误示例:
grok {
match => { message => "%{COMMONAPACHELOG}" } # message 没加引号
}如果你用了自定义 pattern:
grok {
patterns_dir => ["/etc/logstash/patterns"]
match => { "message" => "%{MY_PATTERN}" }
}可能问题:
.patterns✅ 排查:
ls -l /etc/logstash/patterns典型现象:
_grokparsefailure 标签出现✅ 验证方法:
bin/logstash -e '
input { stdin {} }
filter {
grok {
match => { "message" => "%{YOUR_PATTERN}" }
}
}
output { stdout { codec => rubydebug } }
'Grok 本质是 正则 + 命名捕获
❌ 错误示例:
(?✅ 正确:
(?✅ 检查版本:
logstash --version重点看:
SyntaxErrorpattern not foundGrok::PatternError在线工具:
本地工具:
bin/logstash-plugin list | grep grokLogstash 配置文件必须是 合法 Ruby Hash 结构
input {
...
}
filter {
grok {
match => {
"message" => "%{COMMONAPACHELOG}"
}
}
}
output {
...
}| 错误 | 原因 | 解决 |
|---|---|---|
_grokparsefailure | 表达式不匹配 | 调整 Grok |
pattern not found | 模式名错误 | 检查拼写 |
Expected one of | 语法错误 | 检查括号、引号 |
| 无输出 | 匹配失败 | 用 debug 工具 |
| 权限错误 | patterns_dir | chmod / chown |
你可以直接贴出:
我可以 直接帮你写出可用的 Grok 表达式 ✅