diff --git a/templates/config.alloy.erb b/templates/config.alloy.erb index 9132dab..6637418 100644 --- a/templates/config.alloy.erb +++ b/templates/config.alloy.erb @@ -31,6 +31,12 @@ loki.process "parse_hostname" { } } } + // Fallback: Set hostname explicitly if not parsed + stage.static_labels { + values = { + hostname_fallback = system.hostname, // e.g., fm002 + } + } } // Refine labels @@ -50,11 +56,11 @@ loki.relabel "add_labels" { source_labels = ["hostname"] target_label = "hostname" } - //rule { - // source_labels = ["hostname_fallback"] - // target_label = "hostname" - // action = "replace" - // replacement = "${__label:hostname_fallback}" // Only if hostname is unset + rule { + source_labels = ["hostname_fallback"] + target_label = "hostname" + action = "replace" + replacement = "${__label:hostname_fallback}" // Only if hostname is unset } }