Hi,
hoping someone on here might be able to assist me.
I have setup an alloy service that is currently setup to scrape a load of application log directories and forward these various log files to Loki.
It more or less works, I have a
stage.regex: successfully finds the logs files and extracts the appname from the path
values: sets an app label to the extracted appname.
This seems to work, what I am trying to do is include a couple of semi-static labels for a couple of server based metrics.
e.g. Environment and Hostname.
I can confirm that on my Alloy service (Docker container) both the environment variables are set and return values but I cannot figure out how to get them into the log entries output in Loki.
I tried:
loki.process
…..
values = {
app = “appname”,
environment = sys.env(“ENVIRONMENT”)
}
this has no effect, although similar config does work for scraping docker logs.
Anyone got any ideas?
loki.source.file "apps" {
targets = local.file_match.apps.targets
forward_to = [loki.process.apps.receiver]
tail_from_end = true
}
loki.process "apps" {
stage.regex {
expression = `\/opt\/apps\/(?<appname>[^\/]+)\/logs\/.*`
source = "filename"
}
values = {
app = "appname",
}
forward_to = [loki.write.main.receiver]
}
This works, but if I add in the environment tag into the values it does not get included in the entries.
Many thanks!