What is a Prometheus target?

Better Stack Team
Updated on November 29, 2024

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:

  1. Static configuration
    Targets are explicitly listed in the prometheus.yml file:
    yaml scrape_configs: - job_name: 'web-servers' static_configs: - targets: - '192.168.1.101:8080' - '192.168.1.102:8080'

  2. 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.
  • Address label conflicts by using relabeling to modify or filter labels.

Best practices

  • Use meaningful job_name values (e.g., web-servers or db-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.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

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 us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build 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.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github