Open
Description
What's wrong?
Digital ocean droplets have two IP public and private. All node-exporters are listening on private IP. Hoverer, parts of droplets, has only public IP.
Steps to reproduce
If a private IP is available, Prometheus tries to scrape it; in other cases, it uses a public IP.
Now I started to use Alloy, and these rules don't work. Alloy always uses public IP for scraping.
Used to Prometheus, I had this relabeling rule, which works well:
# Prioritize private IPs
- source_labels: [__meta_digitalocean_private_ipv4]
target_label: __address__
replacement: "${1}:9100"
action: replace
# Fallback to public IP only if private IP is missing
- source_labels:
[__meta_digitalocean_private_ipv4, __meta_digitalocean_public_ipv4]
regex: ^$, (.*)
target_label: __address__
replacement: "${1}:9100"
// Prioritize private IPs
rule {
source_labels = ["__meta_digitalocean_private_ipv4"]
target_label = "__address__"
replacement = "${1}:9100"
action = "replace"
}
// Fallback to public IP only if private IP is missing
rule {
source_labels = ["__meta_digitalocean_private_ipv4", "__meta_digitalocean_public_ipv4"]
regex = "^$, (.*)"
target_label = "__address__"
replacement = "${1}:9100"
action = "replace"
}
The full part of configuration:
discovery.relabel "node_exporter" {
targets = discovery.digitalocean.node_exporter.targets
rule {
source_labels = ["__meta_digitalocean_private_ipv4"]
regex = "^$,(.*)|(.+),.*"
target_label = "__address__"
replacement = "${1}:9100"
}
rule {
source_labels = ["__meta_digitalocean_region"]
regex = "fra1"
action = "keep"
}
rule {
source_labels = ["__meta_digitalocean_status"]
regex = "^$|active"
action = "keep"
}
rule {
source_labels = ["__meta_digitalocean_tags"]
regex = ".*,monitoring_yes,.*"
action = "keep"
}
rule {
source_labels = ["__meta_digitalocean_droplet_name"]
target_label = "instance"
}
rule {
source_labels = ["__meta_digitalocean_region"]
target_label = "region"
}
rule {
target_label = "datacenter"
replacement = "digital_ocean"
}
rule {
source_labels = ["__meta_digitalocean_size"]
target_label = "size"
}
}