Glossary · S

Scraping (Prometheus)

Pull-based collection in which Prometheus or a compatible agent periodically fetches metrics from the HTTP endpoints of its targets.

By Obseria TeamUpdated

Definition

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

  1. Discovery: Prometheus determines the list of targets from static config or service discovery.
  2. Relabeling: relabel_configs filter targets and set labels before the scrape.
  3. Request: the server fetches the endpoint within the scrape_timeout.
  4. Parsing: the response in Prometheus text, OpenMetrics or protobuf format is parsed.
  5. Metric relabeling: metric_relabel_configs can drop or rewrite individual series.
  6. 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_seconds for slow targets.
  • Control cardinality at the source. Use metric_relabel_configs to drop unused series and set sample_limit to protect the server from a target that suddenly exposes millions of series. See cardinality.
  • Handle labels deliberately. honor_labels decides 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.

Frequently asked questions

The scrape interval is the time between two scrapes of the same target. Prometheus defaults to one minute; many teams use 15 or 30 seconds for finer resolution.

The synthetic metric up is 0 when the last scrape of a target failed, for example because of a timeout, a connection error or an invalid response. It is the standard signal for an unreachable target.

Only if the server can reach them over the network. Otherwise run an agent or Prometheus in agent mode inside the network that scrapes locally and forwards data via remote write.

relabel_configs runs before the scrape and acts on targets and their labels. metric_relabel_configs runs after the scrape and acts on the individual series, for example to drop unwanted metrics.

Put these concepts into practice

Try Obseria free for 14 days, with OpenTelemetry and no proprietary agents.