11.prometheus监控之黑盒(blackbox)监控
一、黑盒监控
"白盒监控"--需要把对应的Exporter程序安装到被监控的目标主机上,从而实现对主机各种资源及其状态的数据采集工作。
但是由于某些情况下操作技术或其他原因,不是所有的Exporter都能部署到被监控的主机环境中,最典型的例子是监控全国网络质量的稳定性,通常的方法是使用ping操作,对选取的节点进行ICMP测试,此时不可能在他人应用环境中部署相关的Exporter程序。针对这样的应用的场景,Prometheus社区提供了黑盒解决方案,Blackbox Exporter无须安装在被监控的目标环境中,用户只需要将其安装在与Prometheus和被监控目标互通的环境中,通过HTTP、HTTPS、DNS、TCP、ICMP等方式对网络进行探测监控,还可以探测SSL证书过期时间。
blackbox_exporter:
- Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集
二、安装方法
2.1 二进制安装(二选一)
https://prometheus.io/download/#blackbox_exporter
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.23.0/blackbox_exporter-0.23.0.linux-amd64.tar.gz tar zxvf blackbox_exporter-0.23.0.linux-amd64.tar.gz
mkdir /opt/prometheus -p
mv blackbox_exporter-0.23.0.linux-amd64 /opt/prometheus/blackbox_exporter # 创建用户
useradd -M -s /usr/sbin/nologin prometheus
# 修改文件夹权限
chown prometheus:prometheus -R /opt/prometheus # 创建systemd服务
cat <<"EOF" >/etc/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target [Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/blackbox_exporter/blackbox_exporter \
--config.file "/opt/prometheus/blackbox_exporter/blackbox.yml" \
--web.listen-address ":9115"
Restart=on-failure [Install]
WantedBy=multi-user.target
EOF # 启动
systemctl daemon-reload
systemctl start blackbox_exporter
systemctl enable blackbox_exporter
2.2 docker安装(二选一)
创建配置文件,config.yml中监控方式用不到的可以删除,例如pop3、ssh之类
mkdir /data/blackbox_exporter/ cat >/data/blackbox_exporter/config.yml<<"EOF"
modules:
http_2xx:
prober: http
http:
method: GET
http_post_2xx:
prober: http
http:
method: POST
tcp_connect:
prober: tcp
pop3s_banner:
prober: tcp
tcp:
query_response:
- expect: "^+OK"
tls: true
tls_config:
insecure_skip_verify: false
grpc:
prober: grpc
grpc:
tls: true
preferred_ip_protocol: "ip4"
grpc_plain:
prober: grpc
grpc:
tls: false
service: "service1"
ssh_banner:
prober: tcp
tcp:
query_response:
- expect: "^SSH-2.0-"
- send: "SSH-2.0-blackbox-ssh-check"
irc_banner:
prober: tcp
tcp:
query_response:
- send: "NICK prober"
- send: "USER prober prober prober :prober"
- expect: "PING :([^ ]+)"
send: "PONG ${1}"
- expect: "^:[^ ]+ 001"
icmp:
prober: icmp
icmp_ttl5:
prober: icmp
timeout: 5s
icmp:
ttl: 5
EOF
删除不需要的可以留下:
cat config.yml
modules:
http_2xx:
prober: http
http:
method: GET
http_post_2xx:
prober: http
http:
method: POST
tcp_connect:
prober: tcp
icmp:
prober: icmp
cf代理状态码非200
http_2xx:
prober: http
timeout: 5s
http:
method: GET
preferred_ip_protocol: "ip4"
注意:使用preferred_ip_protocol: "ip4" 可以检测cf代理目标在 cloudflare 后面,状态码非200
2.2.1 docker直接运行
sudo docker run -d --restart=always --name blackbox-exporter -p 9115:9115 -v /data/blackbox_exporter:/etc/blackbox_exporter prom/blackbox-exporter:v0.19.0 --config.file=/etc/blackbox_exporter/config.yml
2.2.2 docker-compose运行
cd /data/blackbox_exporter/ cat >docker-compose.yaml <<"EOF"
version: '3.3'
services:
blackbox_exporter:
image: prom/blackbox-exporter
container_name: blackbox_exporter
restart: always
volumes:
- /data/blackbox_exporter:/etc/blackbox_exporter
ports:
- 9115:9115
EOF
启动:docker-compose up -d
查看状态:http://192.168.10.100:9115/
3. Prometheus配置
配置prometheus去采集(拉取)blackbox_exporter的监控样本数据
cd /data/docker-prometheus cat >> prometheus/prometheus.yml <<"EOF" #http配置
- job_name: "blackbox_http"
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://www.baidu.com
- https://www.jd.com
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.10.100:9115 #tcp检查配置
- job_name: "blackbox_tcp"
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets:
- 192.168.10.14:22
- 192.168.10.14:9090
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.10.100:9115 #icmp检查配置 ping
- job_name: "blackbox_icmp"
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets:
- 192.168.10.14
- 192.168.10.100
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.10.100:9115
EOF
重新加载配置:curl -X POST http://localhost:9090/-/reload
检查:
http://192.168.10.14:9090/targets?search=

3.1 监控项
probe_ probe_success # 是否探测成功(取值 1、0 分别表示成功、失败)
probe_duration_seconds # 探测的耗时 # 关于 DNS
probe_dns_lookup_time_seconds # DNS 解析的耗时
probe_ip_protocol # IP 协议,取值为 4、6
probe_ip_addr_hash # IP 地址的哈希值,用于判断 IP 是否变化 # 关于 HTTP
probe_http_status_code # HTTP 响应的状态码。如果发生重定向,则取决于最后一次响应
probe_http_content_length # HTTP 响应的 body 长度,单位 bytes
probe_http_version # HTTP 响应的协议版本,比如 1.1
probe_http_ssl # HTTP 响应是否采用 SSL ,取值为 1、0
probe_ssl_earliest_cert_expiry # SSL 证书的过期时间,为 Unix 时间戳
3.2 触发器配置
添加blackbox_exporter触发器告警规则
cat >> prometheus/rules/blackbox_exporter.yml <<"EOF"
groups:
- name: Blackbox
rules:
- alert: 黑盒子探测失败告警
expr: probe_success == 0
for: 1m
labels:
severity: critical
annotations:
summary: "黑盒子探测失败{{ $labels.instance }}"
description: "黑盒子检测失败,当前值:{{ $value }}"
- alert: 请求慢告警
expr: avg_over_time(probe_duration_seconds[1m]) > 1
for: 1m
labels:
severity: warning
annotations:
summary: "请求慢{{ $labels.instance }}"
description: "请求时间超过1秒,值为:{{ $value }}"
- alert: http状态码检测失败
expr: probe_http_status_code <= 199 OR probe_http_status_code >= 400
for: 1m
labels:
severity: critical
annotations:
summary: "http状态码检测失败{{ $labels.instance }}"
description: "HTTP状态码非 200-399,当前状态码为:{{ $value }}"
- alert: ssl证书即将到期
expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 30
for: 1m
labels:
severity: warning
annotations:
summary: "证书即将到期{{ $labels.instance }}"
description: "SSL 证书在 30 天后到期,值:{{ $value }}" - alert: ssl证书即将到期
expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 3
for: 1m
labels:
severity: critical
annotations:
summary: "证书即将到期{{ $labels.instance }}"
description: "SSL 证书在 3 天后到期,值:{{ $value }}" - alert: ssl证书已过期
expr: probe_ssl_earliest_cert_expiry - time() <= 0
for: 1m
labels:
severity: critical
annotations:
summary: "证书已过期{{ $labels.instance }}"
description: "SSL 证书已经过期,请确认是否在使用"
EOF
检查配置并加载:
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.yml curl -X POST http://localhost:9090/-/reload
http://192.168.10.14:9090/rules
http://192.168.10.14:9090/alerts?search=
4.grafana dashboard图形化展示
https://grafana.com/grafana/dashboards/13659-blackbox-exporter-http-prober/

https://grafana.com/grafana/dashboards/9965

检测总耗时这个图行点编辑---找到Options--把Legend里面的值从{{env}}_{{name}}修改为{{instance}}

11.prometheus监控之黑盒(blackbox)监控的更多相关文章
- Prometheus基于consul自动发现监控对象 https://www.iloxp.com/archive/11/
Prometheus 监控目标为什么要自动发现 频繁对Prometheus配置文件进行修改,无疑给运维人员带来很大的负担,还有可能直接变成一个“配置小王子”,即使是配置小王子也会存在人为失误的情况 ...
- Prometheus笔记(二)监控go项目实时给grafana展示
欢迎加入go语言学习交流群 636728449 Prometheus笔记(二)监控go项目实时给grafana展示 Prometheus笔记(一)metric type 文章目录 一.promethe ...
- incubator-dolphinscheduler 如何在不写任何新代码的情况下,能快速接入到prometheus和grafana中进行监控
一.prometheus和grafana 简介 prometheus是由谷歌研发的一款开源的监控软件,目前已经贡献给了apache 基金会托管. 监控通常分为白盒监控和黑盒监控之分. 白盒监控:通过监 ...
- Prometheus的监控解决方案(含监控kubernetes)
prometheus的简介和安装 Prometheus(普罗米修斯)是一个开源系统监控和警报工具,最初是在SoundCloud建立的.自2012年成立以来,许多公司和组织都采用了普罗米修斯,该项目拥有 ...
- 基于Prometheus搭建SpringCloud全方位立体监控体系
前提 最近公司在联合运维做一套全方位监控的系统,应用集群的技术栈是SpringCloud体系.虽然本人没有参与具体基础架构的研发,但是从应用引入的包和一些资料的查阅大致推算出具体的实现方案,这里做一次 ...
- 基于Prometheus和Grafana打造业务监控看板
前言 业务监控对许许多多的场景都是十分有意义,业务监控看板可以让我们比较直观的看到当前业务的实时情况,然后运营人员可以根据这些情况及时对业务进行调整操作,避免业务出现大问题. 老黄曾经遇到过一次比较尴 ...
- 基于 prometheus 的微服务指标监控
基于prometheus的微服务指标监控 服务上线后我们往往需要对服务进行监控,以便能及早发现问题并做针对性的优化,监控又可分为多种形式,比如日志监控,调用链监控,指标监控等等.而通过指标监控能清晰的 ...
- 简单4步,利用Prometheus Operator实现自定义指标监控
本文来自Rancher Labs 在过去的文章中,我们花了相当大的篇幅来聊关于监控的话题.这是因为当你正在管理Kubernetes集群时,一切都会以极快的速度发生变化.因此有一个工具来监控集群的健康状 ...
- 使用Prometheus搞定微服务监控
最近对服务进行监控,而当前监控最流行的数据库就是 Prometheus,同时 go-zero 默认接入也是这款数据库.今天就对 go-zero 是如何接入 Prometheus ,以及开发者如何自己定 ...
- Golang 基于Prometheus Node_Exporter 开发自定义脚本监控
Golang 基于Prometheus Node_Exporter 开发自定义脚本监控 公司是今年决定将一些传统应用从虚拟机上迁移到Kubernetes上的,项目多而乱,所以迁移工作进展缓慢,为了建立 ...
随机推荐
- 记录--20行js就能实现逐字显示效果???-打字机效果
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 效果演示 横版 竖版 思路分析 可以看到文字是一段一段的并且独占一行,使用段落标签p表示一行 一段文字内,字是一个一个显示的,所以这里每一 ...
- 记录--post为什么会发送两次请求?
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 在前段时间的一次面试中,被问到了一个如标题这样的问题.要想好好地去回答这个问题,这里牵扯到的知识点也是比较多的. 那么接下来这篇文章我们就 ...
- JavaScript知识总结 闭包篇
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 1. 对闭包的理解 闭包是指有权访问另一个函数作用域中变量的函数,创建闭包的最常见的方式就是在一个函数内创建另一个函数,创建的函数可以访问 ...
- LocalDate获取指定月的上个月的第一天和最后一天
LocalDate date = LocalDate.of(2022, 8, 30); LocalDate lastMonth = date.minusMonths(1); // 当前月份减1 Loc ...
- Docker部署之使用docker-compose部署(全新的干净的服务器,从0开始搭建)
部署环境准备 安装yum # 安装yum工具 yum install -y yum-utils device-mapper-persistent-data lvm2 --skip-broken 安装d ...
- FPT:又是借鉴Transformer,这次多方向融合特征金字塔 | ECCV 2020
论文提出用于特征金字塔的高效特征交互方法FPT,包含3种精心设计的特征增强操作,分别用于借鉴层内特征进行增强.借鉴高层特征进行增强以及借鉴低层特征进行增强,FPT的输出维度与输入一致,能够自由嵌入到各 ...
- 新零售SaaS架构:客户管理系统的应用架构设计
客户管理系统的应用架构设计 应用层定义了软件系统的应用功能,负责接收用户的请求,协调领域层能力来执行任务,并将结果返回给用户,功能模块包括: 客户管理:核心功能模块,负责收集和更新客户信息,包括个人资 ...
- Final Countdown 题解
Problem Link 简要题意 把一个数不断减一直到变成零,每个数位变化一次需要一秒. 比如 \(300\) 变成 \(299\) 需要 \(3\) 秒. 求把一个数变成零要多少秒. 思路 对于每 ...
- #线段树#洛谷 4269 [USACO18FEB]Snow Boots G
题目传送门 分析 模型转换一下,能通过当且仅当最长的无法通过段小于 \(d\),(这点应该是此题的精华吧) 那么按照最大深度从小到大排序,双指针在线段树上删除无法通过段,求最长区间即可 代码 #inc ...
- Git 分支管理:优化版本控制与应急处理的关键策略
使用 Git 分支:轻松管理不同版本和应对紧急情况的最佳实践 使用 Git 分支 在 Git 中,分支是主仓库的新/独立版本. 假设你有一个大型项目,需要对其进行设计更新. 没有使用 Git 时: 复 ...