RousselTMLEARNING

Article · Alloy: From Discovery to Expertise

Discovery

1. Discovery #

Auto-detection of targets via Kubernetes, Consul, or static files.

Finding targets automatically #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud

In a modern environment, targets appear and disappear without warning. Rather than listing addresses, this task goes to the discovery.* components, which publish a list of targets in targets.

The metrics chain in Alloy
ComponentSource
discovery.kubernetesPods, services, nodes… through the Kubernetes API
discovery.dockerDocker daemon containers
discovery.fileJSON or YAML files maintained by another tool
discovery.httpAn API returning targets
discovery.dnsDNS records
discovery.processProcesses of the machine

What is a target? #

A target is a simple object of labels. __address__ gives the address. Labels starting with __ are internal: they serve relabeling, then disappear before storage. You can read them in the UI, on the component page.

Example with a file #

A team describes its targets in a file, without touching the Alloy configuration:

[
  {
    "targets": ["app-1:8080", "app-2:8080"],
    "labels": { "equipe": "plateforme", "env": "prod" }
  }
]
discovery.file "applis" {
  files            = ["/etc/alloy/cibles/*.json"]
  refresh_interval = "30s"
}

discovery.relabel "applis" {
  targets = discovery.file.applis.targets

  rule {
    source_labels = ["env"]
    regex         = "dev"
    action        = "drop"
  }

  rule {
    target_label = "cluster"
    replacement  = "paris"
  }
}

Result observed in the Alloy UI, for each target: __address__, env=lab, equipe=plateforme and cluster=paris. dev targets are discarded.

action = "drop" discards what matches, "keep" keeps only that. A rule with no action replaces: it writes replacement to target_label.

Example on Kubernetes #

We keep only annotated pods and turn internal metadata into lasting labels:

discovery.kubernetes "pods" {
  role = "pod"
}

discovery.relabel "annotes" {
  targets = discovery.kubernetes.pods.targets

  rule {
    source_labels = ["__meta_kubernetes_pod_annotation_prometheus_io_scrape"]
    regex         = "true"
    action        = "keep"
  }

  rule {
    source_labels = ["__meta_kubernetes_namespace"]
    target_label  = "namespace"
  }

  rule {
    source_labels = ["__meta_kubernetes_pod_name"]
    target_label  = "pod"
  }
}
Pitfall: without an explicit rule, __meta_* labels disappear. If you want namespace and pod in your metrics, you must copy them, as above.

📄 Grafana Alloy: Metrics Collection (Prometheus & Ecosystem) →

My progress

  • ⏱ Estimated time : ≈ 7 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

Grafana Alloy

An open-source, vendor-neutral telemetry collector designed to replace Grafana Agent, fully compatible with OpenTelemetry (OTel).

Recommended Articles

Collecting logs into Loki: Alloy, Promtail, Docker and OpenTelemetry

Send logs to Loki: Grafana Alloy, Promtail, the Docker driver, OTLP, good labels, parsing and enr...

Grafana Alloy: collecting and transforming telemetry

Learn how to use Grafana Alloy to collect, transform and route logs, metrics and traces. Discover...

Grafana Alloy: collecting system metrics and local logs

Learn how to configure Grafana Alloy to monitor the server it runs on, with a focus on configurat...

Ingesting metrics into VictoriaMetrics: scraping, vmagent and remote write

All the ways to feed VictoriaMetrics: remote write from Prometheus, built-in scraping, vmagent an...

Alloy and the Grafana Labs ecosystem: which component for which tool?

The map of Alloy integrations with Faro, Beyla, k6, Loki, Mimir, Tempo, Pyroscope, Database Obser...

Grafana Alloy vs OpenTelemetry Collector: Which One Should You Choose?

A detailed comparison between Grafana Alloy and the OpenTelemetry Collector. Discover the strengt...

Grafana Alloy vs Grafana Agent vs Promtail: which one to choose?

Discover how telemetry collectors have evolved in the Grafana ecosystem. A detailed comparison of...

Grafana Alloy best practices: optimizing your telemetry collection

Discover the golden rules for configuring Grafana Alloy robustly: modularity, secrets management,...

Grafana Alloy: The importance of Self-Monitoring

Discover why and how to configure Grafana Alloy so that it monitors itself, collecting its own lo...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!