My advice is to only write the expression that matches what you need.
You want to match lines that have the word LOCALRELAY in them, so do just that:
counter localrelay_hit
/LOCALRELAY/ {
localrelay_hit ++
}
And see how that goes.
I see you want to match user, too, so put that in the regexp:
counter localrelay_hit by user
/LOCALRELAY \w+\* from (\w+)/ {
locarelay_hit[$1]++
}
I am deliberately being vague with the rest of the match, but having just written that I think your \S* after LOCALRELAY is not correct.
Try the regex-golang website! You should be able to get your expression to match the line you pasted.
I just played around a bit there and ended up with ->
.*\*Exceeded LOCALRELAY limit\* from (?P<user>\w+)
in the regular expression field,and your log line in the text to match, and saw the user field in the results.
You also have localrelay as a dimension on the metric, but you only ever match the string LOCALRELAY. Is that intentional? If not, then don't record it.
BTW your first mtail is pretty good, looks like you understand the syntax already!
There is a regression test called 'ex_test.go' in the source that runs mtail on some log examples and checks the output is as expected. You could try to use that to test your program; but also there's some flags to mtail to help with this too, e.g. --one_shot which should simulate running mtail against your log input which you can use to validate it.
Thanks for the email. If there's anything that gets in your way as you try to test your program, please let me know.