Scraping is the pull-based collection method of Prometheus: at a fixed interval, the server sends an HTTP request to each configured target, reads the metrics in the exposition format and stores every value as a timestamped sample. Targets are found through static configuration or service discovery and receive labels such as job and instance.
What is scraping?
Scraping is the process by which Prometheus collects metrics. Instead of applications pushing data to the monitoring system, Prometheus pulls it: at a configured interval it sends an HTTP GET request to each target, typically to the path /metrics, parses the response and appends every value as a new sample to the matching time series. A target can be an application with a built-in metrics endpoint or an exporter that translates metrics from another system.
The same model is used by the OpenTelemetry Collector's Prometheus receiver and by many agents and Prometheus-compatible backends, so the concepts below apply far beyond Prometheus itself.
The scrape cycle
- Discovery: Prometheus determines the list of targets from static config or service discovery.
- Relabeling:
relabel_configsfilter targets and set labels before the scrape. - Request: the server fetches the endpoint within the
scrape_timeout. - Parsing: the response in Prometheus text, OpenMetrics or protobuf format is parsed.
- Metric relabeling:
metric_relabel_configscan drop or rewrite individual series. - Storage: samples are written to the TSDB with the scrape timestamp.
For each scrape, Prometheus also records synthetic series such as up (1 if the scrape succeeded, 0 otherwise), scrape_duration_seconds and scrape_samples_scraped. Alerting on up == 0 is the simplest way to detect a target that is down or unreachable.
A scrape configuration
global:
scrape_interval: 30s
scrape_timeout: 10s
scrape_configs:
- job_name: checkout
metrics_path: /metrics
static_configs:
- targets: ["checkout-1:8080", "checkout-2:8080"]
labels:
env: production
If not set, the global scrape_interval defaults to one minute and scrape_timeout to ten seconds. Every scraped series receives the target labels job (the job name) and instance (host and port). Intervals between 15 and 60 seconds are common. Shorter intervals give finer resolution but multiply the number of samples and the load on targets.
Timestamps matter as well. Prometheus assigns the time of the scrape to every sample unless the target provides explicit timestamps, which is rarely recommended. When a target disappears or a series is no longer exposed, Prometheus writes a staleness marker, so queries stop returning the old value instead of carrying it forward. Queries without a fresh sample look back at most five minutes by default before treating a series as absent. This is why a scrape interval longer than a few minutes leads to gaps in graphs.
Service discovery
In dynamic environments, target lists change constantly. Prometheus integrates with Kubernetes, major cloud providers, Consul, DNS and file-based lists. With kubernetes_sd_configs, Prometheus watches the Kubernetes API and discovers nodes, services, pods, endpoints or ingresses. Kubernetes metadata such as namespace, pod name or annotations is available as meta labels starting with __meta_ and can be turned into regular labels through relabeling. The Prometheus Operator adds ServiceMonitor and PodMonitor resources, so teams declare scrape targets next to their deployments.
Best practices
- Use one interval per server where possible. Mixed intervals complicate
rate()windows; a range should cover at least several scrape intervals. - Keep the timeout below the interval and watch
scrape_duration_secondsfor slow targets. - Control cardinality at the source. Use
metric_relabel_configsto drop unused series and setsample_limitto protect the server from a target that suddenly exposes millions of series. See cardinality. - Handle labels deliberately.
honor_labelsdecides whether labels from the target win over server-side labels; it is typically enabled for the Pushgateway and federation. - Secure endpoints. Metrics can reveal internal details. Use network policies, TLS and authentication where needed.
Pull versus push
Scraping has clear advantages: the server knows which targets should exist and detects missing ones, targets need no configuration about the monitoring backend, and endpoints are easy to inspect manually. Push models, such as OTLP or Prometheus remote write, fit better for short-lived jobs, serverless functions and environments where the server cannot reach targets. Many setups combine both: an agent scrapes local targets and pushes the result to a central backend. Prometheus itself supports this with its agent mode, which scrapes and forwards via remote write without running queries or storing data long term.
How Obseria helps
The Obseria Agent and OpenTelemetry Collectors scrape Prometheus endpoints with standard scrape configs and Kubernetes service discovery, then forward the metrics to Obseria. The Obseria Pipeline can drop or aggregate high-cardinality series before storage. In Obseria you query them with PromQL alongside traces and logs. See Kubernetes monitoring and the Prometheus integration.