Refactor OpenWRT configuration: add host argument and correct optional flag

This commit is contained in:
2025-08-02 00:19:07 +03:00
parent e87e5c1e91
commit c420447669
2 changed files with 49 additions and 4 deletions

View File

@@ -4,7 +4,8 @@ import.file "openwrt" {
}
openwrt.openwrt {
forward_to = [prometheus.remote_write.metrics_service.receiver]
forward_to = [prometheus.remote_write.metrics_service.receiver]
host = "NAMU-PC" // Default host, can be overridden by environment variable
}
prometheus.remote_write "metrics_service" {

View File

@@ -1,7 +1,51 @@
import.http "libstd" {
url = "https://git.kkarolis.lt/karolis/Alloy/raw/branch/main/lib/std.alloy"
}
declare "openwrt" {
argument "forward_to" {
optinal = false
comment = "Where to forward the scraped metrics"
optional = false
comment = "Where to forward the scraped metrics"
}
argument "host" {
optional = true
comment = "The host OpenWRT collector is running on"
default = sys.env("GCLOUD_FM_COLLECTOR_ID")
}
libstd.load_host_config "load_config" {
host = argument.host.value
config_file = "OpenWRT/config.yaml"
}
discovery.relabel "openwrt_node_exporter" {
targets = libstd.load_host_config.load_config.config.targets
rule {
source_labels = ["hostname"]
target_label = "__address__"
replacement = "$1:9100"
}
rule {
action = "labelmap"
regex = "hostname"
replacement = "instance"
}
rule {
action = "labeldrop"
regex = "hostname"
}
}
prometheus.scrape "openwrt_node_exporter" {
targets = discovery.relabel.openwrt_node_exporter.output
forward_to = argument.forward_to.value
}
export "targets" {
value = discovery.relabel.openwrt_node_exporter.output
}
}