Hey everyone,
my Problem this time is that i want to have a repeating variable in Grafana that repeats for every different Log name. So Label Log and value server.log, app.log, error.log. I do not want to aggregate them. I want this per app and there can be multiple on one machine.
Server1
Prod
C:\Program\app\logs*.log
C:\Program\app\webserver\logs*.log
Test
C:\Program\apptest\logs*.log
C:\Program\apptest\webserver\logs*.log
Server 2
…
“filename” Label that is created automatically looks like this then
C:\Program\app\webserver\logs\server.log
This gives me an error if i want to repeat over filename cause of escaping as the \ is not doubled in that path.
My idea to solve this was to use just the filename so “log” = “server.log”,“app.log” etc. to then search this as filename =~ “.*$log” in Grafana.
I tried filtering the filename like this:
stage.regex {
source = “filename”
expression = “(?[^\\]+)$”
}
stage.static_labels {
values = {
Log = “log”,
}
}
And i guess this should work but i couldn’t confirm because i only get log like this.
So my question is how do i get this label “Log” to have the different values of filenames?
Or does anyone have another simpler solution for the problem that can be done without matching everything individually?
Couple of issues:
- Your regex group capture is incomplete (no group name).
- If you use double quote in
stage.regex
you need to double escape special character. I recommend using ` character instead.
- static_labels is for setting hard coded labels. You want
stage.labels
instead.
I would also recommend using a label name that makes more sense, perhaps filename_basename? But this is up to you.
Something like this (not tested):
stage.regex {
expression = `(?<basename_parsed>[^\\]+)$`
source = "filename"
}
stage.labels {
values = { filename_basename = "basename_parsed" }
}
Thanks @tonyswumac ,
This works like a charm. I had the capture group in before but tried some stuff out. Also thanks for the tipps.
Also do you happen to Know where you can read up on this?
stage.labels {
values = { filename_basename = “basename_parsed” }
}
I didn’t find anything that really explains ho to do this in the Documentation.
If you are referring to the stage.labels block, you can find it here loki.process | Grafana Alloy documentation
If you are referring to the filename
label being provided by the source.file block, it’s here: loki.source.file | Grafana Alloy documentation
those i found it was more about the creating a Label our of a Capture group. Now that i did it i rembember seeing it once in an example somewhere but i didn’t connect it to my problem.