【prometheus】- Blackbox_exporter监控web页面

2018/07 作者:ihunter 0 0

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.gzscp blackbox_exporter monitor:/usr/local/bin/12

创建用户

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/1234

服务启动脚本

cat >> /usr/lib/systemd/system/blackbox_exporter.service << EOF
[Unit]
Description=Prometheus blackbox exporter
After=local-fs.target network-online.target network.targetWants=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.ymlRestart=on-failure

[Install]
WantedBy=multi-user.targetEOF1234567891011121314151617

启动服务

systemctl daemon-reload
systemctl enable blackbox_exporter
systemctl start blackbox_exporter123

docker方式部署

git clone https://github.com/prometheus/blackbox_exporter.gitdocker build -t blackbox_exporter .docker run -d -p 9115:9115 --name blackbox_exporter -v `pwd`:/config blackbox_exporter --config.file=/config/blackbox.yml123

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"12345678910111213141516

一般情况下都会以非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/-/reload1234567891011121314151617

参考

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


赞(3) 更多分享

上篇: 万能数据收集器 Fluentd
下篇: Consul+Prometheus系统监控之注册发现