HAProxy Exporter for Prometheus 是一个简单的服务,用于抓取 HAProxy 的统计数据(stats)并通过 HTTP 暴露,供 Prometheus 采集。注意:此导出器已退役,所有受支持版本的 HAProxy 均已内置 Prometheus 导出器模块,可在构建时通过单个标志集成到二进制文件中,并提供原生 Prometheus 端点。建议尽快迁移至 HAProxy 内置支持。
$http_proxy/$https_proxy/$no_proxy)配置 HTTP 代理该导出器原本适用于需要将 HAProxy 运行指标(如连接数、请求量、健康状态等)导出至 Prometheus 进行监控的场景。但由于 HAProxy 官方已在 2.0.0 及以上版本内置 Prometheus 导出功能,此独立导出器已停止维护。仅推荐在无法升级 HAProxy 或临时过渡场景下使用,长期应迁移至官方内置方案。
通过命令行启动导出器,核心配置通过标志(flags)指定:
bash./haproxy_exporter [flags]
查看所有可用标志:
bash./haproxy_exporter --help
| 参数 | 说明 | 示例 |
|---|---|---|
--haproxy.scrape-uri | HAProxy stats 接口的 URI(必须包含 ;csv 参数,需引号包裹) | --haproxy.scrape-uri="http://localhost:5000/haproxy?stats;csv" |
--no-haproxy.ssl-verify | 禁用 HTTPS 抓取时的证书验证 | --no-haproxy.ssl-verify |
--http.proxy-from-env | 从环境变量(HTTP_PROXY/HTTPS_PROXY/NO_PROXY)读取代理配置 | --http.proxy-from-env |
--web.config.file | TLS 和基本认证配置文件路径(格式参考 https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md%EF%BC%89 | --web.config.file=web-config.yml |
1. HTTP Stats URL 抓取
若 HAProxy stats 接口路径为 /baz(非默认):
bashhaproxy_exporter --haproxy.scrape-uri="http://localhost:5000/baz?stats;csv"
抓取远程 HAProxy 实例:
bashhaproxy_exporter --haproxy.scrape-uri="http://haproxy.example.com/haproxy?stats;csv"
2. 带基本认证的 Stats 接口
若 stats 接口受基本认证保护,可在 URI 中包含凭据:
bashhaproxy_exporter --haproxy.scrape-uri="http://user:pass@haproxy.example.com/haproxy?stats;csv"
为避免凭据暴露在进程列表中,可通过文件传递参数:
bashecho '--haproxy.scrape-uri=http://user:pass@haproxy.example.com/haproxy?stats;csv' > args haproxy_exporter @args
3. HTTPS 抓取
抓取 HTTPS 接口,禁用证书验证(仅测试环境使用):
bashhaproxy_exporter --no-haproxy.ssl-verify --haproxy.scrape-uri="https://haproxy.example.com/haproxy?stats;csv"
4. 通过代理抓取远程 HAProxy
设置环境变量并启用代理支持:
bashexport HTTP_PROXY="http://proxy:3128" haproxy_exporter --http.proxy-from-env --haproxy.scrape-uri="http://haproxy.example.com/haproxy?stats;csv"
5. Unix Socket 抓取
若 HAProxy 配置了 Unix Socket stats 接口(如 /run/haproxy/admin.sock):
bashhaproxy_exporter --haproxy.scrape-uri=unix:/run/haproxy/admin.sock
通过 Docker 容器运行导出器(镜像托管于 Quay 和 Docker Hub):
bashdocker run -p 9101:9101 quay.io/prometheus/haproxy-exporter:latest \ --haproxy.scrape-uri="http://user:pass@haproxy.example.com/haproxy?stats;csv"
注:容器默认暴露 9101 端口,需映射至主机端口以提供 Prometheus 采集。
导出器支持通过配置文件启用 TLS 和基本认证,需通过 --web.config.file 指定配置文件路径,配置格式参考 https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md%E3%80%82
HAProxy 2.0.0 及以上版本内置 Prometheus 导出模块,2.4 及以上版本可通过构建时添加 USE_PROMEX=1 标志启用:
bashmake TARGET=linux-glibc USE_PROMEX=1
预构建版本(如 https://hub.docker.com/_/haproxy%EF%BC%89%E9%80%9A%E5%B8%B8%E5%B7%B2%E9%BB%98%E8%AE%A4%E5%90%AF%E7%94%A8%E6%AD%A4%E5%8A%9F%E8%83%BD%E3%80%82
在 haproxy.cfg 中添加前端配置,暴露 /metrics 端点:
haproxyfrontend stats bind *:8404 # 暴露指标的端口 http-request use-service prometheus-exporter if { path /metrics } # Prometheus 指标端点 stats enable # 传统 stats 页面(可选) stats uri /stats # 传统 stats 页面路径(可选) stats refresh 10s # stats 页面刷新间隔(可选)
重启 HAProxy 后,访问 http://<haproxy-ip>:8404/metrics 即可获取 Prometheus 格式指标。
Apache License 2.0,详见 https://github.com/prometheus/haproxy_exporter/blob/main/LICENSE%E3%80%82
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
不支持 push
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务