Sub topic 8
Verifying targets and fixing failed scrapes
This chapter assumes you have a working prometheus.yml with at least one node job, a running node_exporter, and shell access to the Prometheus host. You should be comfortable with systemctl, journalctl, and curl. By the end you will be able to tell whether Prometheus is collecting data, find out why it is not, and fix the common causes.
What "a healthy target" means
A target is one endpoint that Prometheus scrapes, such as server1.example.com:9100. On every scrape Prometheus makes an HTTP GET request, parses the response, and stores the samples. It also records a few synthetic metrics about the scrape itself. You can query these like any other series.
| Metric | Meaning |
|---|---|
| `up` | 1 if the scrape succeeded, 0 if it failed |
| `scrape_duration_seconds` | How long the scrape took |
| `scrape_samples_scraped` | Number of samples the target returned |
| `scrape_samples_post_metric_relabeling` | Samples left after relabeling and dropping |
up is the most useful one. A value of 0 means the HTTP request failed, timed out, returned a non-200 status, or returned a body that could not be parsed. It does not tell you which of these happened. For that you need the target's lastError field.
Checking targets in the web interface
Open http://<prometheus-host>:9090/targets. Each job is listed with its targets and these columns:
- Endpoint: the full URL that was scraped, including the path.
- State: UP, DOWN, or UNKNOWN (the first scrape has not happened yet).
- Labels: the labels attached after relabeling, including
instanceandjob. - Last scrape and Scrape duration.
- Error: the reason for the last failure. It is empty when the target is healthy.
You can also query the same information from the command line. This is useful over SSH or in scripts:
curl -s http://localhost:9090/api/v1/targets \
| jq -r '.data.activeTargets[] | [.labels.job, .scrapeUrl, .health, .lastError] | @tsv'To see failures across all jobs in the expression browser, run:
# Every target that failed its last scrape
up == 0
# Number of failing targets per job
count by (job) (up == 0)Reading the error message
Most failures fall into a handful of categories. The error text points at the layer that is broken.
| Error text | Likely cause |
|---|---|
| `connection refused` | Nothing listens on that address and port, or the exporter is bound to `127.0.0.1` only |
| `context deadline exceeded` | The request hit `scrape_timeout`. A firewall dropping packets or a very slow exporter are typical causes |
| `no such host` | The DNS name in `targets` does not resolve from the Prometheus host |
| `no route to host` | Routing problem or a firewall rejecting the traffic |
| `server returned HTTP status 404 Not Found` | Wrong `metrics_path`, or the service is not an exporter |
| `server returned HTTP status 401` or `403` | The target requires authentication that the scrape job does not supply |
| `x509: certificate signed by unknown authority` | The job uses `https` and Prometheus does not trust the certificate |
| `expected value after metric` or `invalid metric type` | The response is not valid Prometheus text format |
A systematic way to debug
Work from the target outward. Always test from the Prometheus host, because a request that works from your laptop proves nothing about the network path Prometheus uses.
Step 1: is the service running?
On the monitored server:
systemctl status node_exporter
journalctl -u node_exporter -n 50 --no-pager
ss -tlnp | grep 9100The ss output should show a listener on *:9100 or on the server's public address. A listener on 127.0.0.1:9100 accepts only local connections. In that case Prometheus gets connection refused from another host. Fix this by changing the exporter's --web.listen-address flag.
Step 2: can the Prometheus host reach it?
On the Prometheus host, request the exact URL shown in the Endpoint column:
curl -sS -m 5 -o /dev/null -w '%{http_code} %{time_total}s\n' \
http://server1.example.com:9100/metricsA 200 with a short time means the network path is fine. curl also reports the same kind of error text that Prometheus shows. If it hangs until the timeout, check firewalls on the server (for example firewall-cmd --list-ports or ufw status) and any cloud security group rules.
Step 3: is the configuration right?
Validate the file before every reload. It catches YAML mistakes and bad rule file paths:
promtool check config /etc/prometheus/prometheus.ymlThen reload without restarting. Prometheus re-reads its configuration when it receives SIGHUP:
sudo systemctl reload prometheusIf the unit has no ExecReload, use sudo kill -HUP $(pidof prometheus). Alternatively start Prometheus with --web.enable-lifecycle and run curl -X POST http://localhost:9090/-/reload. If the new file is invalid, Prometheus keeps the old configuration and logs the error, so check journalctl -u prometheus after a reload.
Scrape settings that cause trouble
These options belong in the job and override the global defaults:
scrape_configs:
- job_name: node
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets: ['server1.example.com:9100']scrape_timeoutmust not exceedscrape_interval. Prometheus rejects the configuration otherwise. The default timeout is 10s.metrics_pathdefaults to/metrics. Some applications serve metrics elsewhere.schemedefaults tohttp. Settinghttpsagainst a plain HTTP port produces TLS errors, and the reverse produces unparseable responses.- Write targets as
host:portwith no scheme and no path. Puttinghttp://insidetargetsis an error.
When the target is UP but data is missing
A healthy up value does not guarantee that your dashboard works. Check these in order:
- Time range. A panel set to "Last 5 minutes" shows nothing for a target added one minute ago.
- Label mismatch. A query such as
up{job="nodes"}returns nothing when the job is namednode. Run the bare metric name first, then add matchers one at a time. - Rate window too short.
rate(...[1m])with a 15s interval needs at least two samples inside the window. Use a window of at least four times the scrape interval, such as[1m]for 15s or[5m]for general use. - Dropped samples. Compare
scrape_samples_scrapedwithscrape_samples_post_metric_relabeling. A large gap means relabeling rules are discarding series. - Clock skew. If a server's clock is badly wrong, check
node_time_seconds - time()for that instance. Prometheus stamps samples with its own time, but skew still breaks comparisons with logs.
Stale series after a target is removed
When a target disappears, Prometheus marks its series stale at the next scrape. Queries stop returning those series right away. The old samples stay in storage until retention removes them. If a dead server keeps showing in a panel, the panel is probably using a time range or a function such as max_over_time that looks back at old data.
Exercise
A target on server2.example.com:9100 shows DOWN with the error context deadline exceeded. systemctl status node_exporter on server2 reports active, and curl http://localhost:9100/metrics works there. What should you test next, and what is the most likely cause?
Show answer
Run curl -m 5 http://server2.example.com:9100/metrics from the Prometheus host. The exporter works locally, so the problem is on the network path. A timeout rather than a refusal usually means a firewall or security group is silently dropping traffic to port 9100. Open the port for the Prometheus host's address and recheck /targets.
Exercise
You add a new job to prometheus.yml with scrape_interval: 15s and scrape_timeout: 30s, then run sudo systemctl reload prometheus. The new job never appears. What happened, and which command would have caught it?
Show answer
A scrape timeout longer than the interval is invalid, so Prometheus rejected the new configuration and kept running with the old one. promtool check config /etc/prometheus/prometheus.yml would have reported the error before the reload, and journalctl -u prometheus shows it afterwards.