惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
月光博客
月光博客
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
博客园 - 叶小钗
腾讯CDC
B
Blog RSS Feed
博客园 - Franky
爱范儿
爱范儿

杂烩饭

使用RetroArch玩步步高电子词典游戏 彻底删除CCLibrary 在 Nginx 中禁止 IP 直连与域名暴露 使用 RustFS 自建对象存储 使用cURL命令管理对象存储(s3) AGENTS.md Prometheus使用kubeconfig做k8s的service 自动发现监控 定制Windows系统镜像iso 使用create-dmg工具制作dmg安装包 使用create-dmg工具制作dmg安装包 - 技术栈 superpowers Nexus仓库搭建记录 Git Merge代码冲突的解决方式 在 Linux 系统中安装与配置 OpenVPN:从入门到精通 使用 Easytier-web 管理 easytier 节点 ingress-nginx 去除指定context path 在macOS上使用MusicPlayer2听本地音乐 Kubernetes 1.34 + RHEL10 + Cilium + kube-vip 高可用集群部署 使用腾讯云CLS收集TKE(k8s)业务日志 容器调试工具之BusyBox 无Docker环境进行容器镜像操作 使用kubeadm部署一套高可用k8s集群1.34 for Ubuntu 正在运行的Docker容器增加端口映射 轻量级组网工具WireGuard 在Kubernetes中部署一个单节点Elasticsearch 使用openssl制作自签名双向认证(mTLS)证书 minio自建对象存储 ingress-nginx 使用自定义的nginx配置 P12格式证书与PEM格式转换 记一次MySQL字符集转换导致的故障
使用blackbox-exporter做域名监控
张理坤 · 2025-06-17 · via 杂烩饭

对应的 blackbox exporter 的配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
valid_status_codes: [200]
method: GET
preferred_ip_protocol: "ip4"
http_post_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
method: POST
preferred_ip_protocol: "ip4"
tcp_connect:
prober: tcp
timeout: 2s
icmp:
prober: icmp
timeout: 2s
icmp:
preferred_ip_protocol: "ip4"
http_accept_404:
prober: http
timeout: 10s
http:
valid_status_codes: [200, 201, 204, 404]
method: GET
preferred_ip_protocol: "ip4"
no_follow_redirects: false

其中:

  • http_2xx: get 请求 200 认为是正常的
  • http_post_2xx: post 请求 200 认为是正常的
  • tcp_connect: 测试端口是不是通的
  • icmp:能否 ping 通
  • http_accept_404: get 请求,404 也认为是正常的

配置 Prometheus

HTTP 监控 只有 200 是正常请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- job_name: 'http_get'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['https://test.com']
labels:
app: 生产环境域名
- targets: ['http://1.1.1.1:8888']
labels:
app: 测试IP地址
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: blackbox-exporter.monitor.svc:9115
- source_labels: [__param_target]
target_label: instance

HTTP 监控 2xx 和 404 都认为是正常请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- job_name: 'http_get_with_404'
metrics_path: /probe
params:
module: [http_accept_404]
static_configs:
- targets: ['https://test.com']
labels:
app: 生产环境域名
- targets: ['http://1.1.1.1:8888']
labels:
app: 测试IP地址
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: blackbox-exporter.monitor.svc:9115
- source_labels: [__param_target]
target_label: instance

TCP 端口监控

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
- job_name: port
honor_timestamps: true
params:
module:
- tcp_connect
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /probe
scheme: http
follow_redirects: true
static_configs:
- targets: ['1.1.1.1:8662']
labels:
app: 密码机-1
- targets: ['2.2.2.2:8662']
labels:
app: 密码机-2
relabel_configs:
- source_labels: [__address__]
separator: ;
regex: (.*)
target_label: __param_target
replacement: $1
action: replace
- source_labels: [__param_target]
separator: ;
regex: (.*)
target_label: addr
replacement: $1
action: replace
- source_labels: [__param_target]
separator: ;
regex: (.+):(.*)
target_label: port
replacement: $2
action: replace
- separator: ;
regex: (.*)
target_label: __address__
replacement: blackbox-exporter:9115
action: replace

验证

1
curl "http://blackbox-exporter.monitor:9115/probe?target=http://a.test.com&module=http_accept_404"

PromQL 常用查询

1
2
3
4
5
6
7
8

(probe_ssl_earliest_cert_expiry{project="project1",env="prod"} - time()) / 60 / 60 / 24


probe_success{project="project1",env="prod"}


probe_duration_seconds{project="project1",env="prod"}

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 杂烩饭