Prometheus 监控方案学习笔记(九):使用 Prometheus 进行黑盒监控( Blackbox Exporter 的安装和配置)
huty
2022年12月02日 · 阅读 1,650
安装 Blackbox Exporter
Docker Compose 方式
- 目录准备
创建目录:
mkdir -pv /apps/exporter/blackbox-exporter/conf
- 编辑 docker-compose.yml 文件
vim /apps/exporter/blackbox-exporter/docker-compose.yml
version: "3"
services:
blackbox-exporter:
image: prom/blackbox-exporter:v0.22.0
container_name: prometheus-blackbox-exporter
hostname: blackbox-exporter
restart: always
ports:
- 9115:9115
volumes:
- /apps/exporter/blackbox-exporter/conf:/config
environment:
- config.file=/config/blackbox.yml
networks:
default:
external:
name: prometheus
- 编辑 blackbox.yml 文件
官方示例:https://github.com/prometheus/blackbox_exporter/blob/master/example.yml
vim /apps/exporter/blackbox-exporter/conf/blackbox.yml
modules:
http_2xx:
prober: http
timeout: 10s
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
- 配置 docker 网段 prometheus
检查是否存在 prometheus 网段:
docker network list
若不存在,则创建:
docker network create prometheus --subnet 10.21.22.0/24
- 启动 blackbox-exporter 容器
cd /apps/exporter/blackbox-exporter
docker-compose up -d
- 检查 blackbox-exporter 容器状态、查看 blackbox-exporter 容器日志
cd /apps/exporter/blackbox-exporter
docker-compose ps
docker-compose logs -f
配置 Blackbox Exporter
配置 Prometheus
- 编辑 prometheus.yml 文件
scrape_configs:
## 探针
- job_name: 'blackbox'
metrics_path: /probe
scrape_interval: 30s
params:
module: [http_2xx]
static_configs:
- targets:
- 需要监控的URL1,如:https://hty1024.com
- 需要监控的URL2,如:https://www.hty1024.com
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
- 重启 prometheus
cd /apps/prometheus
docker-compose restart
- 检查 blackbox-exporter 探针是否正常运行
访问 Prometheus WebUI 的 targets 页面,检查 job 状态
配置 Grafana
登录 Grafana,导入对应的看板即可。
看板获取地址:https://grafana.com/grafana/dashboards/?dataSource=prometheus&search=Blackbox+Exporter
注意: 看板导入后需要修改数据源的ID
- 数据源查看方式: 在 Grafana 中进入
数据源详情
页面,浏览器 URL 的最后一段字符为该数据源的 ID。 如 URL 为grafana/datasources/edit/6lbJpCb4z
时,6lbJpCb4z
即为当前数据源的 ID - 数据源替换方式: 编辑看板,查看看板的 JSON 数据,替换
datasource
中的uid
分类:
Prometheus 监控体系
标签:
Prometheus
评论已关闭