categraf mtail语法支持问题

Viewed 103

求支持!!!!!!!!!
用“|”有效,能获取到指标:
counter system_out_of_memory_error by logfile
/(Out of memory|out_of_memory)/ {
system_out_of_memory_error[getfilename()]++
}

用“&”无效,无法获取指标:
counter system_memory_error by logfile
/(memory&error)/ {
system_memory_error[getfilename()]++
}

categraf版本:v0.2.36

5 Answers

你可以写成/.*memory.*error/ {
system_memory_error[getfilename()]++
}
image.png

文档可以参考https://flashcat.cloud/docs/content/flashcat-monitor/categraf/plugin/mtail/

我爱你飞哥!

看到这个问题,我是懵的。//内填写正则,所以完全符合预期呢,你的理解是?

我想要达到的效果是:日志中含memory 且含error关键词才推送指标,两个条件必须满足。
我通过:echo "---xxx-----test memory xxx2 ooooooooooooo error ooooooo" >> /var/log/messages
没有达到预期,也就是prom没获取到指标

认真读我写的那段话哈://内填写正则,话说,这个正则 /(memory&error)/ 本来就无法匹配 ---xxx-----test memory xxx2 ooooooooooooo error ooooooo

找我的理解/(Out of memory|out_of_memory)/可以,那直接把“|”改成“&”就好。
大佬你丢个正则砸死我吧,我写不动了。。。

好的没问题,微信发个200红包,这都可以安排 🤝 今天正好有5分钟时间不用给资本家打工,帮你想这个正则

你可以用chatgpt 把内容和规则写进去他给生成

有道理,哈哈

image.png

匹配日志行的正则表达式

/$ts:datetime [[]$severity:word[]] [[$module:word]] [.] $message:.$/ {

将匹配到的日志内容作为指标名称,出现次数作为指标值,指定标签为 module 和 severity

counter["log_count"]++ by $module, $severity
}

牛,但是看不懂,能用吗?

不得行 我还在改
加载2个模版
counter module
counter severity
counter log_count_total by module, severity

/$ts:datetime [(\w+)] [(\w+ \w+)] [.] $message:./ {
module[$1]++
severity[$2]++
log_count_total[$1][$2]++
}
在运行时报错
2023/04/11 18:37:56 runtime.go:84: unmarking test.mtail
2023/04/11 18:37:56 runtime.go:84: unmarking test1.logs
2023/04/11 18:37:56 runtime.go:132: Compile errors for test1.mtail:
compile failed for test1.mtail:
test1.mtail:6:3-11: Index taken on unindexable expression
test1.mtail:7:3-13: Index taken on unindexable expression

我也有这个需求 我看折腾折腾搞一搞