What is a Prometheus target?
In Prometheus, a target is an endpoint or service that Prometheus monitors by scraping metrics. These metrics are exposed in a Prometheus-compatible format, typically over an HTTP or HTTPS endpoint. Targets are configured in the prometheus.yml
file and identified by two labels:
instance
: Specifies the target’s address (e.g.,192.168.1.101:9090
).job
: Groups targets logically (e.g.,web-servers
).
Configuring targets
Targets can be defined either statically or dynamically:
Static configuration
Targets are explicitly listed in theprometheus.yml
file:
yaml scrape_configs: - job_name: 'web-servers' static_configs: - targets: - '192.168.1.101:8080' - '192.168.1.102:8080'
Dynamic service discovery
Prometheus integrates with platforms like Kubernetes, AWS, or Consul to discover targets automatically.
Example for Kubernetes:
yaml scrape_configs: - job_name: 'kubernetes-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] action: keep regex: 'web'
Inspecting targets
To view the status of targets:
- Open the Prometheus web UI and navigate to Status > Targets.
- Details include:
- State: Whether the target is UP
or DOWN
.
- Labels: Assigned labels such as job
and instance
.
- Last Scrape: Timestamp of the last scrape.
- Scrape Duration: Time taken for the scrape.
Troubleshooting
- If a target is
DOWN
, check its/metrics
endpoint and verify it exposes metrics in Prometheus format. - For missing targets:
- Static targets: Confirm the correct IP and port in
prometheus.yml
. - Dynamic targets: Verify service discovery and relabeling configurations.
- Static targets: Confirm the correct IP and port in
- Address label conflicts by using relabeling to modify or filter labels.
Best practices
- Use meaningful
job_name
values (e.g.,web-servers
ordb-cluster
) to organize targets logically. - Set appropriate scrape intervals to balance resource usage and data freshness:
yaml scrape_interval: 30s scrape_timeout: 10s
- Use relabeling to exclude unnecessary targets and optimize resource usage.
- Monitor target states and configure alerts for targets that are consistently
DOWN
.
Targets are the foundation of Prometheus monitoring. Proper configuration and management ensure reliable and efficient metric collection from your systems.
-
Limitations of Prometheus Labels
Prometheus labels are a powerful feature used to add dimensional data to metrics. However, improper use or lack of understanding of their limitations can lead to inefficiencies, high resource consu...
Questions -
How To Manage Prometheus Counters
Prometheus counters are metrics that only increase or reset to zero. They are ideal for tracking values like requests, errors, or completed tasks. Managing counters effectively ensures accurate and...
Questions -
What is the Difference Between a Gauge and a Counter?
Gauges and counters are two core metric types in Prometheus. They serve different purposes and are used to track different kinds of data. 1. Counter A counter is a metric that only increases over t...
Questions -
What are Prometheus Labels?
What are Prometheus labels? Prometheus labels are key-value pairs used to add metadata to metrics, making them more descriptive and allowing flexible queries. They enable Prometheus to organize, fi...
Questions
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github