Hey there,
Im new to alloy, tried to setup promtail before but I read it‘s in maintenance mode and would rather start with alloy.
My config file is below.
What I like to achieve is to process each docker container with it‘s own regex, or maybe add multiple docker containers to the same regex match if their logging format is the same. I have 40 docker containers which all log in different formats.
Should i change the way i currently configured the discovery process? e.g. make multiple separat ones so i can choose to send them for processing or not?
Or can I leave it like it is and make a catch all one for any containers that do not meet the regex of the matched lines?
The homeassistant match also does not work, i currently dont get any logs passed to loki. If i send the logs without processing and remove that block i‘m getting all logs.
// ###############################
// #### Logging Configuration ####
// ###############################// Discover Docker containers and extract metadata.
discovery.docker “linux” {
host = “unix:///var/run/docker.sock”
}// Define a relabeling rule to create a service name from the container name.
discovery.relabel “logs_integrations_docker” {
targets =rule { source_labels = ["__meta_docker_container_name"] regex = "/(.*)" target_label = "container_name" } rule { target_label = "instance" replacement = constants.hostname }
}
// Configure a loki.source.docker component to collect logs from Docker containers.
loki.source.docker “default” {
host = “unix:///var/run/docker.sock”
targets = discovery.docker.linux.targets
relabel_rules = discovery.relabel.logs_integrations_docker.rules
forward_to = [loki.process.docker_logs.receiver]
// forward_to = [loki.write.local.receiver]
}loki.process “docker_logs” {
stage.match {
selector ={container_name="homeassistant"}
stage.regex { expression = "^(?P<ts>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d+)\\s+(?P<level>[A-Z]+)\\s+\\((?P<thread>[^)]+)\\)\\s+\\[(?P<logger>[^\\]]+)\\]\\s+(?P<message>.*)$" } stage.timestamp { source = "timestamp" format = "2006-01-02 15:04:05.000" location = "Local" }
}
stage.match {
selector ={container_name="nginx"}
stage.regex { expression = "^(?P<remote_addr>\\S+) - (?P<remote_user>\\S+) \\[(?P<time_local>[^\\]]+)\\] \"(?P<request>[^\"]+)\" (?P<status>\\d{3}) (?P<body_bytes_sent>\\d+) \"(?P<http_referer>[^\"]*)\" \"(?P<http_user_agent>[^\"]*)\"" } stage.timestamp { source = "time_local" format = "02/Jan/2006:15:04:05 -0700" location = "Local" }
}
forward_to = [loki.write.local.receiver]
}loki.write “local” {
endpoint {
url = “http://loki:3100/loki/api/v1/push”
}
}