prometheus target 显示 down 通常因配置端口错误,如将 node_exporter 的 9100 误写为 9090;应通过 curl 检查连通性、确认服务监听端口、确保 targets 包含正确地址和端口。

prometheus.yml 配置文件写错端口导致 target 一直显示 DOWN
Prometheus 启动后页面里 target 状态是 DOWN,十有八九不是服务没起来,而是配置里写的 targets 地址根本连不通——最常见的是把被监控服务的端口写错了,比如把 node_exporter 的 9100 写成 9090(那是 Prometheus 自己的端口)。
检查方法很简单:在 Prometheus 服务器上直接 curl http://localhost:9100/metrics,看能不能拿到指标文本。如果返回 Connection refused,说明要么服务没跑,要么端口不对。
- 确认
node_exporter确实运行中:systemctl status node_exporter - 确认它监听的是你配置的地址+端口:
ss -tlnp | grep :9100 -
prometheus.yml里static_configs下的targets必须带端口,不能只写localhost - 如果被监控机不在本机,别用
localhost,得填对方真实 IP 或可解析的主机名
systemd 服务启动失败,journalctl 报 failed to start Prometheus Server
用 systemd 管理 Prometheus 时,systemctl start prometheus 失败,journalctl -u prometheus -n 50 -f 里看到这句,基本是启动参数或配置路径出问题。
Prometheus 启动必须指定配置文件位置,而 systemd service 文件里常漏掉 --config.file,或者路径写错、权限不够。
- 检查 service 文件里的
ExecStart=行,确保包含类似--config.file=/etc/prometheus/prometheus.yml - 确认该配置文件存在,且 Prometheus 进程用户(比如
prometheus用户)有读取权限:ls -l /etc/prometheus/prometheus.yml - 配置文件语法错误也会导致启动失败,手动验证:
/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --dry-run - 别把
prometheus.yml放在用户家目录下,systemd 默认不会读取非系统路径,且权限容易出问题
添加自定义 metrics 时,curl localhost:9090/metrics 看不到新指标
自己写了 exporter 或在应用里暴露了 /metrics,但 Prometheus 拉不到数据,通常不是 Prometheus 没配,而是暴露端点本身没生效。
Prometheus 只负责 HTTP GET,它不关心你用什么语言写,只认响应体是否是合法的 Prometheus 文本格式(以 # HELP 开头、换行分隔、类型声明正确)。
- 先绕过 Prometheus,直接
curl http://your-app:8080/metrics,看返回内容是不是纯文本,有没有乱码、重定向、404 - 检查响应头:
Content-Type必须是text/plain; version=0.0.4(旧版)或text/plain; charset=utf-8(新版也接受),否则 Prometheus 会跳过 - 指标名必须符合命名规范:
my_app_http_requests_total✅,my-app.http.requests❌(不能含点、短横以外的符号) - 如果用 Python 的
prometheus_client,记得调用start_http_server(8000),不是只注册指标就完事
远程存储写入失败,日志里反复出现 failed to send samples to remote storage
启用 remote_write 后,Prometheus 日志里持续报这个错,大概率是目标存储服务不可达,或认证/协议不匹配。
Remote write 是单向推送,Prometheus 不依赖响应内容,只要 HTTP 状态码是 2xx 就认为成功。所以即使远端没存进去,Prometheus 也可能不报错——得看远端日志。
- 确认远端接收服务(如 Thanos Receiver、VictoriaMetrics)已运行,并监听配置中的
url地址和端口 - 如果 url 是
https://,检查证书是否可信;内网常用自签证书,需在remote_write配置里加insecure_skip_verify: true - 注意
queue_config中的max_samples_per_send和batch_send_deadline,设得太小会导致频繁发空包,太大会积压内存 - 默认 remote_write 是异步的,失败不会阻塞本地采集,但积压过多会 OOM——用
prometheus_remote_storage_queue_length指标观察
配置里最容易被忽略的,是所有路径、URL、端口都得对得上——不是“看起来像”,而是网络层真能通、应用层真能解析、格式层真能识别。少一次 curl 验证,就多一个黑盒问题。









