7、blackbox_exporter 软件安装
bloackbox exporter是prometheus社区提供的黑盒监控解决方案,运行用户通过HTTP、HTTPS、DNS、TCP以及ICMP的方式对网络进行探测。这里通过blackbox对我们的站点信息进行采集。
官方下载地址:
https://github.com/prometheus/blackbox_exporter/releases/download/v0.18.0/blackbox_exporter-0.18.0.linux-amd64.tar.gz
# 解压文件
tar xf blackbox_exporter-0.18.0.linux-386.tar.gz
cd blackbox_exporter-0.18.0.linux-386/
# 配置启动文件
vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/montion/blackbox_exporter-0.18.0.linux-386
ExecStart=/montion/blackbox_exporter-0.18.0.linux-386/blackbox_exporter
[Install]
WantedBy=multi-user.target
# 启动
[root@node00 system]# systemctl restart blackbox_exporter
# 查看状态
[root@node00 system]# systemctl status blackbox_exporter
# 开机自启
[root@node00 system]# systemctl enable blackbox_exporter
# 服务端口
9115
2、Prometheus 中集成 blackbox_exporter
#修改配置文件
vim prometheus.yml
- job_name: "blackbox"
metrics_path: /probe
params:
module: [http_2xx] # Look for a HTTP 200 response.
file_sd_configs:
- refresh_interval: 1m
files:
- "/montion/prometheus-2.19.1/conf/blackbox*.yml"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: x.x.x.x:9115
# 添加配置
[root@harbor conf]# pwd
/montion/prometheus-2.19.1/conf
[root@harbor conf]# vim blackbox-dis.yml
- targets:
- https://www.alibaba.com
- https://www.tencent.com
- https://www.baidu.com
- http://x.x.x.x:9104/metrics
# 配置标签
- labels:
role: 百度
targets:
- https://www.baidu.com
- labels:
role: IP 地址
targets:
- https://1.2.5.6
# nginx 案例
- job_name: 'nginx'
static_configs:
- targets:
- x.x.x.x:9913
labels:
app: nginx
role: gateway
metrics_path: /metrics
scrape_timeout: 10s
params:
module: [huawei]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: x.x.x.x:9913
# 重启服务
systemctl restart prometheus.service
# http tcp icmp
- job_name: "http-status"
metrics_path: /probe
params:
module: [http_2xx] # Look for a HTTP 200 response.
file_sd_configs:
- refresh_interval: 1m
files:
- "/opt/prometheus-2.19.1/blackbox/http.yml"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: x.x.x.x:9115
# 模板 [root@SVR-Prometheus01 blackbox]# cat tcp.yml
- labels:
role: 数据库
targets:
- x.x.x.x:3306
- job_name: "tcp-status"
metrics_path: /probe
params:
module: [tcp_connect] # Look for a HTTP 200 response.
file_sd_configs:
- refresh_interval: 1m
files:
- "/opt/prometheus-2.19.1/blackbox/tcp.yml"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: x.x.x.x:9115
-------------------------------------------- 告警
# 证书告警
- name: ssl_expiry.rules
rules:
- alert: SSLCertExpiringSoon
expr: probe_ssl_earliest_cert_expiry{job="blackbox"} - time() < 86400 * 30
for: 10m
# 接口故障告警
groups:
- name: node-export
rules:
- alert: "黑盒探测"
expr: probe_success{job=~"blackbox"} == 0
for: 1m
labels:
env: test
app: test-1
annotations:
description: "{{ $labels.instance }} ({{ $labels.role }})接口故障,请及时进行检查,当前值:{{ $value }}"
3、grafana 配置
导入官方模板:
ID: 9965 13659 11529 11365
插件去官网安装安装在服务器执行
grafana-cli plugins install grafana-piechart-panel