mkdir -pv /apps/exporter/blackbox-exporter/conf
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
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 network list
若不存在,则创建:
docker network create prometheus --subnet 10.21.22.0/24
cd /apps/exporter/blackbox-exporter
docker-compose up -d
cd /apps/exporter/blackbox-exporter
docker-compose ps
docker-compose logs -f
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
cd /apps/prometheus
docker-compose restart
登录 Grafana,导入对应的看板即可。
看板获取地址:https://grafana.com/grafana/dashboards/?dataSource=prometheus&search=Blackbox+Exporter
注意: 看板导入后需要修改数据源的ID
数据源详情
页面,浏览器 URL 的最后一段字符为该数据源的 ID。 如 URL 为 grafana/datasources/edit/6lbJpCb4z
时, 6lbJpCb4z
即为当前数据源的 IDdatasource
中的 uid