Prometheus 官网
https://prometheus.io/download/
blackbox_exporter
blackbox_exporter是Prometheus 官方提供的 exporter,可通过HTTP、HTTPS、DNS、TCP、ICMP 对端点进行可用性等指标探测
blackbox_exporter 官方文档
https://github.com/prometheus/blackbox_exporter
部署blackbox_exporter
1,下载blackbox_exporter
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.22.0/blackbox_exporter-0.22.0.linux-amd64.tar.gz
tar -zvxf node_exporter-1.4.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.4.0.linux-amd64.tar.gz node_exporter
2,查看blackbox_exporter版本信息
/usr/local/blackbox_exporter
./blackbox_exporter --version
3,systemctl管理blackbox_exporter
vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
User=root
Type=simple
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
4,启动、开机启动blackbox_exporter
systemctl start blackbox_exporter && systemctl enable blackbox_exporter
ps -ef |grep blackbox_exporter
5,blackbox_exporter 配置文件
无特殊需求使用默认配置即可
blackbox_exporter 默认集成如下Module(可编辑配置文件自定义Module)
6,http 访问测试(blackbox_exporter默认监听9115端口)
http://192.168.100.167:9115/
blackbox_exporter 探测目标主机命令
1,http get探测目标网站
http://192.168.100.167:9115/probe?module=http_2xx&target=https://www.jd.com/
http://192.168.100.167:9115/probe?module=http_2xx&target=http://192.168.100.234:18080
http get 探测参数介绍
# DNS解析时间,单位 s
probe_dns_lookup_time_seconds 0.011683847
# 探测从开始到结束的时间,单位 s,请求这个页面响应时间
probe_duration_seconds 0.087513035
# HELP probe_failed_due_to_regex Indicates if probe failed due to regex
# TYPE probe_failed_due_to_regex gauge
probe_failed_due_to_regex 0
# HTTP 内容响应的长度
probe_http_content_length 163069
# 按照阶段统计每阶段的时间
#连接时间
probe_http_duration_seconds{phase="connect"} 0.011124773
#处理请求的时间
probe_http_duration_seconds{phase="processing"} 0.022142512
#响应时间
probe_http_duration_seconds{phase="resolve"} 0.011683847
#校验证书的时间
probe_http_duration_seconds{phase="tls"} 0.015542311
#传输时间
probe_http_duration_seconds{phase="transfer"} 0.026364486
# 重定向的次数
probe_http_redirects 0
#是否启用ssl
probe_http_ssl 1
# 返回的状态码
probe_http_status_code 200
# 未压缩的响应主体长度
probe_http_uncompressed_body_length 163069
# http 协议的版本
probe_http_version 1.1
#ip地址哈希值。检测IP地址是否有变化
probe_ip_addr_hash 4.64797816e+08
# 使用的 ip 协议的版本号
probe_ip_protocol 4
#ssl证书过期时间
probe_ssl_earliest_cert_expiry 1.700376737e+09
#上一次ssl证书过期时间
probe_ssl_last_chain_expiry_timestamp_seconds 1.700376737e+09
#ssl证书信息
probe_ssl_last_chain_info{fingerprint_sha256="ec56a7324741024dd5d2be45dab60db3d8f832ff3a92c0304680a58af2ec2f20"} 1
# 是否探测成功
probe_success 1
#ssl 证书版本信息
probe_tls_version_info{version="TLS 1.3"} 1
2,http icmp探测目标地址命令
http://192.168.100.167:9115/probe?module=icmp&target=114.114.114.114
http://192.168.100.167:9115/probe?module=icmp&target=192.168.100.234
3,http icmp探测参数介绍
# 探测从开始到结束的时间,单位 s
probe_duration_seconds 0.010998769
#网络延迟
probe_icmp_duration_seconds{phase="rtt"} 0.010592477
# 是否探测成功
probe_success 1
15s 采集一次,60s采集四次, 计算丢包率
(1-sum_over_time(probe_success{instance=~"223.5.5.5"}[1m])/4)*100
4,http tcp探测目标主机
http://192.168.100.167:9115/probe?module=tcp_connect&target=192.168.100.234:22
http tcp探测参数介绍
# 探测从开始到结束的时间,单位 s
probe_duration_seconds 0.010998769
# 是否探测成功
probe_success 1
Zabbix Web 创建HTTP Agent 监控项
1,创建HTTP Agent监控项
http://192.168.100.167:9115/probe?module=http_2xx&target=https://www.jd.com/
不保留历史数据
2,创建http连接时间相关项目
2.1,监控项预处理
probe_http_duration_seconds{phase="connect"}
3,ssl证书监控项
jd_probe_ssl_earliest_cert_expiry
3.1,ssl证书预处理
probe_ssl_earliest_cert_expiry
4,ssl证书剩余时间监控项
5,http 状态监控项
5.1,http 状态预处理
probe_success
6,http 状态码监控
6.1,http 状态码监控预处理
probe_http_status_code
7,最新数据
http连接时间
probe_http_duration_seconds{phase="connect"}
http处理请求的时间
probe_http_duration_seconds{phase="processing"}
http响应时间
probe_http_duration_seconds{phase="resolve"}
ssl证书过期时间
probe_ssl_earliest_cert_expiry
http连接状态
probe_success 1
http 状态码
probe_http_status_code