Prometheus 部署 Black Exporter 黑盒监控 DNS-TCP-ICMP

简介: 建议软件包安装,二进制安装请自行解决配置问题,docker 安装需考虑网络问题。

建议软件包安装,二进制安装请自行解决配置问题,docker 安装需考虑网络问题。

linux 软件包直接部署

apt install prometheus-blackbox-exporter

二进制部署

# 下载安装
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.23.0/blackbox_exporter-0.23.0.linux-amd64.tar.gz
tar -xvf  blackbox_exporter-0.23.0.linux-amd64.tar.gz
mv blackbox_exporter-0.23.0.linux-amd64/ /usr/local/blackbox_exporter

# 创建配置文件
cat > /data/black_exporter/black_exporter.yml << EOF
modules:
  http_2xx:
    prober: http
    timeout: 20s
    http:
      preferred_ip_protocol: "ip4"
  http_post_2xx_query:
    prober: http
    timeout: 20s
    http:
      preferred_ip_protocol: "ip4" ##使用ipv4
      method: POST
      headers:
        Content-Type: application/json ##header头
      body: '{"hmac":"","params":{"publicFundsKeyWords":"xxx"}}' ##传参
  tls_connect_tls:
    prober: tcp
    timeout: 5s
    tcp:
      tls: true
  tcp_connect:
    prober: tcp
    timeout: 5s
 #
  pop3s_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^+OK"
      tls: true
      tls_config:
        insecure_skip_verify: false
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
  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
    timeout: 20s
EOF

# 配置systemd
cat > /etc/systemd/system/blackbox_exporter.service <<EOF
[Unit]
Description=blackbox_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/blackbox_exporter  --config.file=/data/blackbox-exporter/black-exporter.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

# 启动服务
systemctl enable blackbox_exporter.service 
systemctl start blackbox_exporter.service 
systemctl status blackbox_exporter.service

Docker 部署

docker run --rm \
  -p 9115/tcp \
  --name blackbox_exporter \
  -v $(pwd):/config \
  quay.io/prometheus/blackbox-exporter:latest --config.file=/config/blackbox.yml


# 创建配置文件
cat > /data/docker/blackbox-exporter/black-exporter.yml << EOF
modules:
  http_2xx:
    prober: http
    timeout: 20s
    http:
      preferred_ip_protocol: "ip4"
  http_post_2xx_query:
    prober: http
    timeout: 20s
    http:
      preferred_ip_protocol: "ip4" ##使用ipv4
      method: POST
      headers:
        Content-Type: application/json ##header头
      body: '{"hmac":"","params":{"publicFundsKeyWords":"xxx"}}' ##传参
  tls_connect_tls:
    prober: tcp
    timeout: 5s
    tcp:
      tls: true
  tcp_connect:
    prober: tcp
    timeout: 5s
 #
  pop3s_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^+OK"
      tls: true
      tls_config:
        insecure_skip_verify: false
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
  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
    timeout: 20s
EOF

docker run -d \
  --net myDefault \
  --restart always \
  -p 9115:9115/tcp \
  --name blackbox-exporter \
  -v /data/docker/blackbox-exporter:/config \
  songtianlun/blackbox-exporter:v0.23.0 --config.file=/config/black-exporter.yml

测试使用

curl http://192.168.5.152:9115/probe?target=www.frytea.com&module=http_2xx

prometeus 使用

# https monitor
  - job_name: 'hci-https-monitor'
    metrics_path: /probe
    params:
      module: [tls_connect_tls]
    static_configs:
      - targets:
        - 'https://192.168.5.221:8006'
        - 'https://192.168.5.222:8006'
        - 'https://192.168.5.187:8006'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.19.0.1:9115  # The blackbox exporter's real hostname:port.


# http monitor
  - job_name: 'hci-http-monitor'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        - 'http://192.168.5.221:3000'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.19.0.1:9115  # The blackbox exporter's real hostname:port.

  # icmp 监控
  - job_name: 'hci-icmp-monitor'
    scrape_interval: 1m
    metrics_path: /probe
    params:
      module: [ "icmp" ]
    static_configs:
      - targets:
        - 192.168.5.254
        - 192.168.5.221
        - 192.168.5.222
        - 192.168.5.187
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 10.19.0.1:9115  # The blackbox exporter's real hostname:port.
Grafana 导入 Dashboard-ID:7587

参考文献

目录
相关文章
|
6天前
|
编解码 Prometheus 运维
Prometheus 的监控方法论
【1月更文挑战第24天】
|
6天前
|
存储 Prometheus 监控
Prometheus vs. ELK Stack:容器监控与日志管理工具的较量
随着容器化技术的广泛应用,容器监控与日志管理成为了关键任务。本文将对两种常用工具进行比较与选择,分别是Prometheus和ELK Stack。Prometheus是一款开源的监控系统,专注于时序数据的收集和告警。而ELK Stack则是一套完整的日志管理解决方案,由Elasticsearch、Logstash和Kibana三个组件组成。通过比较它们的特点、优势和适用场景,读者可以更好地了解如何选择适合自己需求的工具。
|
6天前
|
消息中间件 Prometheus 监控
Prometheus实战篇:什么是Exporter
所有可以向Prometheus提供监控样本数据的程序都可以被称为一个Exporter.而Exporter的一个实例称为target,如图下所示, Prometheus通过轮询的方式定期从这些target中获取样本数据
|
6天前
|
Prometheus 监控 Kubernetes
如何用 Prometheus Operator 监控 K8s 集群外服务?
如何用 Prometheus Operator 监控 K8s 集群外服务?
|
6天前
|
Prometheus 监控 Kubernetes
Prometheus Operator 与 kube-prometheus 之二 - 如何监控 1.23+ kubeadm 集群
Prometheus Operator 与 kube-prometheus 之二 - 如何监控 1.23+ kubeadm 集群
|
6天前
|
Prometheus 监控 Cloud Native
应用监控(Prometheus + Grafana)
应用监控(Prometheus + Grafana)
23 2
|
6天前
|
Prometheus 监控 Cloud Native
使用Prometheus配置监控与报警
通过以上步骤,你可以使用Prometheus和Alertmanager实现监控和报警配置,以确保系统在出现性能问题或故障时能够及时通知相关人员。欢迎关注威哥爱编程,一起学习成长。
|
6天前
|
Prometheus Kubernetes 监控
|
6天前
|
Prometheus 监控 Cloud Native
使用 Prometheus 配置 SLO 监控和告警
使用 Prometheus 配置 SLO 监控和告警
|
6天前
|
Prometheus 监控 Java
微服务框架(二十四)Prometheus 监控埋点
此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。 本文为Prometheus 监控埋点 本系列文章中所使用的框架版本为Spring Boot 2.0.3-REL...