Blackbox_exporter概述

Blackbox_exporter概述

blackbox exporter是允许在HTTPHTTPSDNSTCP and ICMP等协议的端点进行黑盒探测的采取器 
官方github: https://github.com/prometheus/blackbox_exporter

Blackbox_exporter 部署

blackbox exporter二进制部署

获取包

wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.12.0/blackbox_exporter-0.12.0.linux-amd64.tar.gz
scp blackbox_exporter monitor:/usr/local/bin/
  • 1
  • 2

创建用户

useradd -M -u 8004 -s /sbin/nologin blackbox_exporter
chown blackbox_exporter.blackbox_exporter /usr/local/bin/blackbox_exporter
mkdir /etc/blackbox_exporter
chown -R blackbox_exporter.blackbox_exporter /etc/blackbox_exporter/
  • 1
  • 2
  • 3
  • 4

服务启动脚本

cat >> /usr/lib/systemd/system/blackbox_exporter.service << EOF
[Unit]
Description=Prometheus blackbox exporter
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target

[Service]
User=blackbox_exporter
Group=blackbox_exporter
Type=simple
ExecStart=/usr/local/bin/blackbox_exporter \\
        --config.file=/etc/blackbox_exporter/blackbox.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

启动服务

systemctl daemon-reload
systemctl enable blackbox_exporter
systemctl start blackbox_exporter
  • 1
  • 2
  • 3

docker方式部署

git clone https://github.com/prometheus/blackbox_exporter.git
docker build -t blackbox_exporter .
docker run -d -p 9115:9115 --name blackbox_exporter -v `pwd`:/config blackbox_exporter --config.file=/config/blackbox.yml
  • 1
  • 2
  • 3

blackbox_exporter configure

配置文件为/etc/blackbox_exporter/blackbox.yml 
blackbox_exporter通过配置文件和命令行标志(例如要加载什么配置文件,监听哪个端口以及日志记录格式和级别)进行配置。 
同时可以运行时动态的重新加载配置文件,当重新加载配置文件失败时,不影响在运行的配置 
重载方式:curl -XPOST http://127.0.0.1:9115/-/reload 
blackbox_exporter 的超时时间由Prometheus配置中的scrape_timeout自动确定,略微减少以允许网络延迟.默认是10s

示例配置:

https://github.com/prometheus/blackbox_exporter/blob/master/example.yml

监控http

vim /etc/blackbox_exporter/blackbox.yml
modules:
  http_2xx:  # http 监测模块
    prober: http
    http:
  http_post_2xx: # http post 监测模块
    prober: http
    http:
      method: POST
  tcp_connect: # tcp 监测模块
    prober: tcp
  ping: # icmp 检测模块
    prober: icmp
    timeout: 5s
    icmp:
      preferred_ip_protocol: "ip4"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

一般情况下都会以非root用户运行blackbox_exporter,Wie了使用icmp prober,需要设置CAP_NET_RAW,即对可执行文件blackbox_exporter执行下面的命令:setcap cap_net_raw+ep /usr/local/bin/blackbox_exporter

prometheus configure

  - job_name: 'http_k8s_master'
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        - http://api.k8s.love
        - http://api.local:8675
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: monitor:9115
curl -XPOST http://127.0.0.1:9090/-/reload
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

参考

http://blog.fleeto.us/content/kubernetes-blackbox-shi-xian-dui-web-he-dns-de-jian-dan-jian-kong 
https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值