共计 1684 个字符,预计需要花费 5 分钟才能阅读完成。
背景需求:公司网站因状态码异常或 SSL 证书过期等问题,导致需要人工介入处理,
效率低且对客户影响较大。因此,亟需一个监控系统来实时检测网站异常,提升响应效率, 并减少对客户的影响。
下面我们就来介绍下相关安装配置过程。
下载成功后台解压,我是解压到了 /usr/local
然后使用 systemctl 启动
vim /etc/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
WorkingDirectory=/usr/local/blackbox_exporter
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
[Install]
WantedBy=multi-user.target
配置文件信息如下:
vim blackbox.yml
modules:
http_2xx:
prober: http
timeout: 30s
http:
preferred_ip_protocol: "ip4"
tls_config:
insecure_skip_verify: true
然后启动 blackbox_exporter
systemctl daemon-reload
systemctl start blackbox_exporter
接入到 prometheus
在配置文件 prometheus.yml 中加入
- job_name: 'bhpc_blackbox_http_2xx'
metrics_path: /probe
params:
module: [http_2xx]
file_sd_configs:
- files:
- /usr/local/prometheus/configs/http_exporter.yml
refresh_interval: 60s
scrape_interval: 45s
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115
然后 reload prometheus 就可以看到加入到相关 job
vim http_exporter.yml
- targets: ['https://www.g6k.cn/']
labels:
services: "测试"
env: httpstatus
配置报警条件
vim http.yml
groups:
- name: Http-Alert
rules:
- alert: "HTTP 的探测异常"
expr: probe_http_status_code >= 400 or probe_http_status_code == 0
for: 1m
labels:
severity: httpstatus
annotations:
description: "http 状态异常, 当前值 {{$value}}"
- alert: Web 访问响应响应时间 >30s
expr: probe_duration_seconds >= 30
for: 5m
labels:
severity: 'httpstatus'
annotations:
summary: Web 响应异常 {{$labels.instance}}
- alert: "SSL 过期通知"
expr: (probe_ssl_earliest_cert_expiry{}-time())/3600/24 < 7
for: 1m
labels:
severity: httpstatus
annotations:
description: "SSL 周内过期, 当前值 {{$value}}"
然后接入到 grafana
接入图标 id 为 13659
效果如下
正文完
发表至: 监控
2024-08-14