Lesson 2 of 9 · 26m
Scrapes, Exporters, and the Last Fifteen Seconds
Configure scrape jobs that reflect reality, understand staleness and scrape failures, and instrument services at the right trust boundary.
Prometheus is pull-based, which surprises people who come from push-based monitoring. The server decides when to collect, the target exposes a /metrics endpoint, and the scrape itself becomes operational evidence. That simplicity is powerful: if Prometheus cannot scrape you, the absence is visible rather than silently dropped in a client queue.
A scrape is a health signal
A minimal job looks ordinary:
scrape_configs:
- job_name: checkout
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
static_configs:
- targets:
- checkout-a.internal:8080
- checkout-b.internal:8080Three deadlines matter. scrape_interval is how often collection is attempted. scrape_timeout is how long one scrape may take. The application response deadline must be shorter than both, or Prometheus will mark samples absent even though the service is technically alive.
The synthetic up metric records whether the scrape succeeded:
up{job="checkout"} == 0Do not alert directly on one blip unless you enjoy noise. A short network hiccup can make one target unavailable for one interval while user traffic is unaffected.
Exporters are adapters, not oracles
Exporters translate systems that cannot natively expose Prometheus metrics: Linux nodes, databases, hardware, queues, blackbox probes. Example node exporter scrape target:
- job_name: node
static_configs:
- targets: ["10.20.0.11:9100", "10.20.0.12:9100"]An exporter is only as trustworthy as its mapping. A database exporter might expose connection counts but lie about replication lag if it queries the wrong privileged view. Read exporter documentation, test against a failure you can induce, and version the exporter like production software.
Service discovery is the real world
Static targets are fine for a lab. Real fleets move. Kubernetes discovery rewrites cluster metadata into scrape labels:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: "true"
- source_labels: [__meta_kubernetes_namespace]
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
target_label: podThis is convenient and dangerous. Kubernetes metadata is high-churn. Keep enough labels to locate the target, but do not blindly import every annotation and owner reference.
Staleness is not the same as absence
When a target disappears, Prometheus marks series stale after a short interval. Queries stop seeing the series rather than freezing at the last value forever. This prevents phantom capacity graphs, but it confuses operators who expect a final zero. A vanished exporter means unknown, not healthy and not necessarily zero.
Scrape the boundary users depend on
Internal application metrics tell you what the service thinks happened. Blackbox probes tell you what a caller experienced:
- job_name: blackbox-https
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ["https://status.example.internal/healthz"]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox-exporter.internal:9115Use both. Whitebox metrics explain internals; blackbox metrics verify externally visible behavior.
Field notes
- Set
scrape_timeoutlower thanscrape_interval; overlapping scrapes create confusing load. - Expensive
/metricshandlers can become a denial-of-service surface when scraped by multiple servers. - Protect metrics endpoints on hostile networks. They often leak versions, build metadata, and operational topology.
- A target with TLS verification disabled should be a conscious exception, not a copied default.
- Do not use Prometheus pull for very short-lived batch jobs; use a Pushgateway carefully or emit job-level metrics to another system.
Was this lesson helpful?