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.
| Component | Source |
|---|---|
discovery.kubernetes | Pods, services, nodes… through the Kubernetes API |
discovery.docker | Docker daemon containers |
discovery.file | JSON or YAML files maintained by another tool |
discovery.http | An API returning targets |
discovery.dns | DNS records |
discovery.process | Processes 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 noactionreplaces: it writesreplacementtotarget_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 wantnamespaceandpodin your metrics, you must copy them, as above.
My progress
Sign in to track your progress and take notes. Sign in
💬 Recent discussions about this course
- Alloy : recevoir de l'OTLP et l'envoyer vers Tempo et Mimir✓ solved · 1 reply(ies)
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...