Blackbox_exporter 监控实现
https://prometheus.io/download/#blackbox_exporter
HTTP/HTTPS : URL/API 可用性检测
TCP :端口监听检测
ICMP :主机存活检测
DNS :域名解析
部署 blackbox exporter
1 2 3 4 5
| wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz
tar xf blackbox_exporter-0.19.0.linux-amd64.tar.gz
ln -sv /apps/blackbox_exporter-0.19.0.linux-amd64 /apps/blackbox_exporter
|
创建 blackbox exporter 启动文件
vim /etc/systemd/system/blackbox-exporter.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [Unit] Description=Prometheus Blackbox Exporter After=network.target
[Service] Type=simple User=root Group=root ExecStart=/apps/blackbox_exporter/blackbox_exporter \ --config.file=/apps/blackbox_exporter/blackbox.yml \ --web.listen-address=:9115 Restart=on-failure
[Install] WantedBy=multi-user.target
|
启动并设置开机自启动
1
| systemctl restart blackbox-exporter.service && systemctl enable blackbox-exporter.service
|
blackbox exporter 实现URL监控
prometheus 调用 blackbox exporter 实现对 URL/ICMP 的监控
Prometheus URL 监控配置
vim /apps/prometheus/prometheus.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| - job_name: 'http_status' metrics_path: /probe params: module: [http_2xx] static_configs: - targets: ['http://www.baidu.com', 'https://yuanshisen.com'] labels: instance: http_status group: web relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: url - target_label: __address__ replacement: 192.168.15.110:9115
|
配置生效
1 2 3 4 5 6 7 8 9
| /apps/prometheus/promtool check config /apps/prometheus/prometheus.yml Checking /apps/prometheus/prometheus.yml SUCCESS: 0 rule file found # 重启服务 systemctl restart prometheus.service
# 访问浏览器 192.168.15.110:9115
|
blackbox exporter 实现 ICMP 监控
Prometheus ICMP 监控配置
vim /apps/prometheus/prometheus.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| - job_name: 'ping_status' metrics_path: /probe params: module: [icmp] static_configs: - targets: ['192.168.3.15', "223.6.6.6"] labels: instance: 'ping_status' group: 'icmp' relabel_configs: - source_labels: [__address__] target_label: param_target - source_labels: [__param_target] target_label: ip - target_label: __address__ replacement: 192.168.15.110:9115
|
配置生效
1 2 3 4 5 6 7 8 9
| /apps/prometheus/promtool check config /apps/prometheus/prometheus.yml Checking /apps/prometheus/prometheus.yml SUCCESS: 0 rule file found # 重启服务 systemctl restart prometheus.service
# 访问浏览器 192.168.15.110:9115
|
blackbox exporter 实现端口监控
端口监控配置
vim /apps/prometheus/prometheus.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| - job_name: 'port_status' metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: ['192.168.15.100:9100', '192.168.15.100:80','192.168.15.100:22'] labels: instance: 'port_status' group: 'port' relabel_configs: - source_labels: [__address__] target_label: param_target - source_labels: [__param_target] target_label: ip - target_label: __address__ replacement: 192.168.15.110:9115
|
配置生效
1 2 3 4 5 6 7 8 9
| /apps/prometheus/promtool check config /apps/prometheus/prometheus.yml Checking /apps/prometheus/prometheus.yml SUCCESS: 0 rule file found # 重启服务 systemctl restart prometheus.service
# 访问浏览器 192.168.15.110:9115
|
grafana 导入模版
- 13587(对于web url 监控展示的效果好,其他弱一些)
- 9965 (除了web url展示的不全面,整体都比较全面)