Sub topic 8
Verifying Targets and Fixing Failed Scrapes
Assume you can edit prometheus.yml, use basic Linux commands, and inspect systemd services. You should also understand TCP ports, HTTP responses, and YAML indentation.
A scrape is Prometheus’s request for metrics from a target. A target is usually an exporter, such as node_exporter, running on a monitored server. Prometheus records the result in the up metric:
up == 1means the last scrape succeeded.up == 0means Prometheus could not collect metrics.- No
upseries usually means the target is not in the loaded configuration or the job has not been discovered.
Check the Targets page
Open the Prometheus web interface and select Status, then Targets. Each target shows its job, address, state, and the last error.
You can also query the same state with the HTTP API:
curl -s http://localhost:9090/api/v1/query \
--data-urlencode 'query=up' | jqThe jq command formats JSON so that it is easier to read. If jq is unavailable, remove the final | jq.
Use labels to inspect one job or instance:
up{job="node"}
up{instance="server1.example.com:9100"}A target address is not necessarily the server’s name alone. It includes the port. If the exporter listens on port 9100, omitting that port causes a connection failure.
Interpret common scrape errors
| Error | Likely cause | First check |
|---|---|---|
| `connection refused` | No process is listening, or a local firewall rejects the connection | `systemctl status node_exporter` |
| `connection timed out` | Routing or firewall rules block the request | Test connectivity from the Prometheus host |
| `no such host` | DNS name cannot be resolved | `getent hosts server1.example.com` |
| `server returned HTTP status 404` | Wrong metrics path | Check the exporter endpoint |
| `context deadline exceeded` | Exporter is slow or unreachable | Test the endpoint and review load |
| `text format parsing error` | Endpoint returned non-Prometheus content | Inspect the response with `curl` |
Test the endpoint from the Prometheus server, not from your workstation:
curl -v --max-time 10 http://server1.example.com:9100/metricsA working endpoint returns HTTP status 200 and text containing metric names such as node_cpu_seconds_total. An HTML login page, proxy error, or empty response indicates that the request is reaching the wrong service.
Reload configuration safely
After changing prometheus.yml, validate the file before reloading Prometheus:
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl reload prometheus
sudo journalctl -u prometheus --since "10 minutes ago"If the configuration is invalid, Prometheus keeps its previous configuration or refuses the reload. Check the service logs and confirm that the file path matches the service’s --config.file option.
Exercise
A target appears on the Targets page with up == 0 and connection refused. What should you check first?
Show answer
Check whether node_exporter is running and listening on port 9100 on the target server with systemctl status node_exporter and a local or remote curl request.