
ribbybibby/ssl-exporterSSL Certificate Exporter是一款用于导出SSL证书Prometheus指标的工具,支持从多种来源收集证书信息,包括TCP探针、HTTPS探针、PEM文件、Kubernetes密钥和Kubeconfig文件。指标带有证书字段标签,可用于构建信息仪表盘和实现灵活的告警路由。
bashdocker pull ribbybibby/ssl-exporter
bashdocker run -p 9219:9219 ribbybibby/ssl-exporter:latest <flags>
访问http://localhost:9219/probe?target=example.com:443可获取example.com的证书指标,ssl_probe_success指标指示探针是否成功。
usage: ssl_exporter [<flags>] Flags: -h, --help 显示上下文相关帮助(也可尝试 --help-long 和 --help-man) --web.listen-address=":9219" Web界面和遥测的监听地址 --web.metrics-path="/metrics" 暴露指标的路径 --web.probe-path="/probe" 暴露探针端点的路径 --config.file="" SSL exporter配置文件路径 --log.level="info" 日志级别,仅记录指定级别及以上的日志,有效值:[debug, info, warn, error, fatal] --log.format="logger:stderr" 设置日志目标和格式,例如:"logger:syslog?appname=bob&local=7" 或 "logger:stdout?json=true" --version 显示应用版本
| 指标名称 | 含义 | 标签 | 支持探针 |
|---|---|---|---|
| ssl_cert_not_after | 对等证书过期时间(Unix时间戳) | serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https |
| ssl_cert_not_before | 对等证书生效时间(Unix时间戳) | serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https |
| ssl_file_cert_not_after | 文件探针发现的证书过期时间(Unix时间戳) | file, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | file |
| ssl_file_cert_not_before | 文件探针发现的证书生效时间(Unix时间戳) | file, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | file |
| ssl_kubernetes_cert_not_after | Kubernetes探针发现的证书过期时间(Unix时间戳) | namespace, secret, key, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | kubernetes |
| ssl_kubernetes_cert_not_before | Kubernetes探针发现的证书生效时间(Unix时间戳) | namespace, secret, key, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | kubernetes |
| ssl_kubeconfig_cert_not_after | Kubeconfig探针发现的证书过期时间(Unix时间戳) | kubeconfig, name, type, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | kubeconfig |
| ssl_kubeconfig_cert_not_before | Kubeconfig探针发现的证书生效时间(Unix时间戳) | kubeconfig, name, type, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | kubeconfig |
| ssl_ocsp_response_next_update | OCSP响应中的nextUpdate值(Unix时间戳) | tcp, https | |
| ssl_ocsp_response_produced_at | OCSP响应中的producedAt值(Unix时间戳) | tcp, https | |
| ssl_ocsp_response_revoked_at | OCSP响应中的revocationTime值(Unix时间戳) | tcp, https | |
| ssl_ocsp_response_status | OCSP响应状态(0=良好,1=已吊销,2=未知) | tcp, https | |
| ssl_ocsp_response_stapled | 连接状态是否包含 stapled OCSP响应(布尔值) | tcp, https | |
| ssl_ocsp_response_this_update | OCSP响应中的thisUpdate值(Unix时间戳) | tcp, https | |
| ssl_probe_success | 探针是否成功(布尔值) | all | |
| ssl_prober | 用于连接目标的探针类型(布尔值) | prober | all |
| ssl_tls_version_info | 使用的TLS版本(恒为1) | version | tcp, https |
| ssl_verified_cert_not_after | 验证链中证书的过期时间(Unix时间戳) | chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https |
| ssl_verified_cert_not_before | 验证链中证书的生效时间(Unix时间戳) | chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https |
通过Prometheus的relabel配置实现目标发现和监控:
yamlscrape_configs: - job_name: "ssl" metrics_path: /probe static_configs: - targets: - example.com:443 - prometheus.io:443 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9219 # SSL exporter地址
若需使用HTTP代理,可通过module参数指定HTTPS探针:
yamlscrape_configs: - job_name: "ssl" metrics_path: /probe params: module: ["https"] # 指定使用HTTPS探针 static_configs: - targets: - example.com:443 - prometheus.io:443 relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: 127.0.0.1:9219
HTTPS探针支持通过环境变量(HTTP_PROXY、HTTPS_PROXY、ALL_PROXY)或模块配置中的proxy_url选项设置代理。
用于监控本地PEM文件中的证书,支持通配符匹配:
bash# 单个文件 curl "localhost:9219/probe?module=file&target=/etc/ssl/cert.pem" # 通配符匹配多个文件 curl "localhost:9219/probe?module=file&target=/etc/ssl/**/*.pem"
在Kubernetes中作为DaemonSet运行以监控节点证书:
yamlscrape_configs: - job_name: "ssl-kubernetes-file" metrics_path: /probe params: module: ["file"] target: ["/etc/kubernetes/**/*.crt"] kubernetes_sd_configs: - role: node relabel_configs: - source_labels: [__address__] regex: ^(.*):(.*)$ target_label: __address__ replacement: ${1}:9219
用于监控Kubernetes中kubernetes.io/tls类型的密钥:
bash# 监控指定命名空间下的密钥 curl "localhost:9219/probe?module=kubernetes&target=kube-system/secret-name" # 通配符匹配 curl "localhost:9219/probe?module=kubernetes&target=kube-system/*" # 匹配kube-system命名空间下所有密钥 curl "localhost:9219/probe?module=kubernetes&target=*/*" # 匹配所有命名空间下所有密钥
凭据获取顺序:
kubeconfig路径$KUBECONFIG环境变量$HOME/.kube/config)用于监控kubeconfig文件中的证书:
bashcurl "localhost:9219/probe?module=kubeconfig&target=/etc/kubernetes/admin.conf"
在Kubernetes中监控节点kubeconfig:
yamlscrape_configs: - job_name: "ssl-kubernetes-kubeconfig" metrics_path: /probe params: module: ["kubeconfig"] target: ["/etc/kubernetes/admin.conf"] kubernetes_sd_configs: - role: node relabel_configs: - source_labels: [__address__] regex: ^(.*):(.*)$ target_label: __address__ replacement: ${1}:9219
通过--config.file参数指定配置文件,支持模块级别的详细配置,格式为YAML:
yamlmodules: [<module>]
yaml# 探针类型(https, tcp, file, kubernetes, kubeconfig) prober: <prober_string> # 探针超时时间 [ timeout: <duration> ] # TLS配置 [ tls_config: <tls_config> ] # 特定探针配置 [ https: <https_probe> ] [ tcp: <tcp_probe> ] [ kubernetes: <kubernetes_probe> ]
yaml# 禁用目标证书验证 [ insecure_skip_verify: <boolean> | default = false ] # 目标CA证书文件 [ ca_file: <filename> ] # 客户端证书文件 [ cert_file: <filename> ] # 客户端密钥文件 [ key_file: <filename> ] # 用于验证目标的主机名 [ server_name: <string> ]
yaml# 用于连接目标的HTTP代理服务器 [ proxy_url: <string> ]
yaml# 对支持的协议(smtp, ftp, imap)在启动TLS前使用STARTTLS命令 [ starttls: <string> ]
yaml# 用于配置探针的kubeconfig文件路径 [ kubeconfig: <string> ]
promqlssl_cert_not_after - time() < 86400 * 7
promqlssl_cert_not_after{cn=~"\*.*"} - time() < 86400 * 7
promqlssl_verified_cert_not_after{chain_no="0"} - time() < 86400 * 7
promqlcount(ssl_cert_not_after) by (instance)
promqlssl_probe_success == 0
chain_no标签按过期时间倒序编号,chain_no="0"表示过期时间最晚的信任链。监控证书过期时,建议使用ssl_verified_cert_not_after{chain_no="0"},因为它反映了客户端实际使用的信任链。
注意:此查询仅反映exporter与目标之间的信任链,实际客户端可能因根证书不同而具有不同的验证链。
可在此处获取跟踪证书过期日期和目标连接错误的简单仪表盘。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务